6.5.5 mysqlimport — A Data Import Program (original) (raw)

6.5.5 mysqlimport — A Data Import Program

The mysqlimport client provides a command-line interface to the LOAD DATA SQL statement. Most options tomysqlimport correspond directly to clauses ofLOAD DATA syntax. SeeSection 15.2.9, “LOAD DATA Statement”.

Invoke mysqlimport like this:

mysqlimport [options] db_name textfile1 [textfile2 ...]

For each text file named on the command line,mysqlimport strips any extension from the file name and uses the result to determine the name of the table into which to import the file's contents. For example, files named patient.txt,patient.text, andpatient all would be imported into a table named patient.

mysqlimport supports the following options, which can be specified on the command line or in the[mysqlimport] and [client] groups of an option file. For information about option files used by MySQL programs, see Section 6.2.2.2, “Using Option Files”.

Here is a sample session that demonstrates use ofmysqlimport:

$> mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
$> ed
a
100     Max Sydow
101     Count Dracula
.
w imptest.txt
32
q
$> od -c imptest.txt
0000000   1   0   0  \t   M   a   x       S   y   d   o   w  \n   1   0
0000020   1  \t   C   o   u   n   t       D   r   a   c   u   l   a  \n
0000040
$> mysqlimport --local test imptest.txt
test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
$> mysql -e 'SELECT * FROM imptest' test
+------+---------------+
| id   | n             |
+------+---------------+
|  100 | Max Sydow     |
|  101 | Count Dracula |
+------+---------------+