~drizzle-trunk/drizzle/development

1994.4.119 by Marisa Plumb
doc fixes and additions
1
LOAD DATA INFILE
1994.4.120 by Marisa Plumb
new load data infile doc
2
=================
3
4
While the INSERT statement loads one record at a time into a table, LOAD DATA INFILE imports data from an external text file into a table, and does so very rapidly. The file name must be given as a literal string.
5
6
For example:
7
8
.. code-block:: mysql
9
10
	LOAD DATA LOCAL INFILE '/home/user/names.txt' INTO TABLE names;
11
12
Then check that your data was loaded correctly:
13
14
.. code-block:: mysql
15
16
	SELECT * FROM names;
17
18
Options
19
--------
20
21
LOAD DATA INFILE has some options that can be used to specify the format for the text file and how the data is imported. Above, the LOCAL option specifies the client machine as the location of the text file. When connecting to a Drizzle server, the file will be read directly from the server as long as the LOCAL option is omitted.
22
23
The REPLACE option replaces table rows with the same primary key in the text file. For example:
24
25
.. code-block:: mysql
26
27
	LOAD DATA LOCAL INFILE '/home/user/names.txt' REPLACE INTO TABLE names;
28
29
The IGNORE option says to skip any rows that duplicate existing rows with the same primary key, and follows the same syntax as REPLACE. The IGNORE number LINES option can be used to ignore lines at the start of the file. For example, you can use IGNORE 1 LINES to skip over a row containing column names:
30
31
.. code-block:: mysql
32
33
	LOAD DATA LOCAL INFILE '/home/user/names.txt' INTO TABLE names IGNORE 1 LINES;
34
35
The FIELDS TERMINATED BY option can be used when importing from a comma separated value (CSV) file. (It specifies that the fields will be separated by a character other than a tab, such as a comma.) For example:
36
37
.. code-block:: mysql
38
39
	LOAD DATA LOCAL INFILE '/home/user/names.csv' REPLACE INTO TABLE names FIELDS TERMINATED BY ',';