4.5.5 mysqlimport — A Data Import Program

The mysqlimport client provides a command-line interface to the LOAD DATA INFILE SQL statement. Most options to mysqlimport correspond directly to clauses of LOAD DATA INFILE syntax. See Section 13.2.6, “LOAD DATA INFILE Syntax”.

Invoke mysqlimport like this:

shell> 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, and patient 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 4.2.6, “Using Option Files”.

Table 4.9 mysqlimport Options

FormatOption FileDescriptionIntroduced
--columns=column_listcolumnsThis option takes a comma-separated list of column names as its value 
--compresscompressCompress all information sent between client and server 
--debug[=debug_options]debugWrite a debugging log 
--debug-checkdebug-checkPrint debugging information when program exits 
--debug-infodebug-infoPrint debugging information, memory, and CPU statistics when program exits 
--default-auth=plugindefault-auth=pluginAuthentication plugin to use5.5.10
--default-character-set=charset_namedefault-character-setSpecify default character set 
--defaults-extra-file=file_name Read option file in addition to usual option files 
--defaults-file=file_name Read only named option file 
--defaults-group-suffix=str Option group suffix value 
--deletedeleteEmpty the table before importing the text file 
--fields-enclosed-by=stringfields-enclosed-byThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--fields-escaped-byfields-escaped-byThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--fields-optionally-enclosed-by=stringfields-optionally-enclosed-byThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--fields-terminated-by=stringfields-terminated-by-- This option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--forceforceContinue even if an SQL error occurs 
--help Display help message and exit 
--host=host_namehostConnect to MySQL server on given host 
--ignoreignoreSee the description for the --replace option 
--ignore-lines=#ignore-linesIgnore the first N lines of the data file 
--lines-terminated-by=stringlines-terminated-byThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--locallocalRead input files locally from the client host 
--lock-tableslock-tablesLock all tables for writing before processing any text files 
--low-prioritylow-priorityUse LOW_PRIORITY when loading the table. 
--no-defaults Read no option files 
--password[=password]passwordPassword to use when connecting to server 
--pipepipeOn Windows, connect to server using named pipe 
--plugin-dir=pathplugin-dir=pathDirectory where plugins are installed5.5.10
--port=port_numportTCP/IP port number to use for connection 
--print-defaults Print defaults 
--protocol=typeprotocolConnection protocol to use 
--replacereplaceThe --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values 
--shared-memory-base-name=nameshared-memory-base-nameThe name of shared memory to use for shared-memory connections 
--silentsilentProduce output only when errors occur 
--socket=pathsocketFor connections to localhost, the Unix socket file to use 
--sslsslEnable SSL for connection 
--ssl-ca=file_namessl-caPath of file that contains list of trusted SSL CAs 
--ssl-capath=dir_namessl-capathPath of directory that contains trusted SSL CA certificates in PEM format 
--ssl-cert=file_namessl-certPath of file that contains X509 certificate in PEM format 
--ssl-cipher=cipher_listssl-cipherList of permitted ciphers to use for SSL encryption 
--ssl-key=file_namessl-keyPath of file that contains X509 key in PEM format 
--ssl-verify-server-certssl-verify-server-certVerify server Common Name value in its certificate against host name used when connecting to server 
--use-threads=#use-threadsNumber of threads for parallel file-loading 
--user=user_name,userMySQL user name to use when connecting to server 
--verbose Verbose mode 
--version Display version information and exit 

Here is a sample session that demonstrates use of mysqlimport:

shell> mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
shell> ed
a
100     Max Sydow
101     Count Dracula
.
w imptest.txt
32
q
shell> 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
shell> mysqlimport --local test imptest.txt
test.imptest: Records: 2  Deleted: 0  Skipped: 0  Warnings: 0
shell> mysql -e 'SELECT * FROM imptest' test
+------+---------------+
| id   | n             |
+------+---------------+
|  100 | Max Sydow     |
|  101 | Count Dracula |
+------+---------------+