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

FormatDescriptionIntroduced
--bind-address=ip_addressUse specified network interface to connect to MySQL Server 
--columns=column_listThis option takes a comma-separated list of column names as its value 
--compressCompress all information sent between client and server 
--debug[=debug_options]Write a debugging log 
--debug-checkPrint debugging information when program exits 
--debug-infoPrint debugging information, memory, and CPU statistics when program exits 
--default-auth=pluginAuthentication plugin to use5.6.2
--default-character-set=charset_nameSpecify default character set 
--defaults-extra-file=file_nameRead option file in addition to usual option files 
--defaults-file=file_nameRead only named option file 
--defaults-group-suffix=strOption group suffix value 
--deleteEmpty the table before importing the text file 
--fields-enclosed-by=stringThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--fields-escaped-byThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--fields-optionally-enclosed-by=stringThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--fields-terminated-by=string-- This option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--forceContinue even if an SQL error occurs 
--helpDisplay help message and exit 
--host=host_nameConnect to MySQL server on given host 
--ignoreSee the description for the --replace option 
--ignore-lines=#Ignore the first N lines of the data file 
--lines-terminated-by=stringThis option has the same meaning as the corresponding clause for LOAD DATA INFILE 
--localRead input files locally from the client host 
--lock-tablesLock all tables for writing before processing any text files 
--login-path=nameRead login path options from .mylogin.cnf5.6.6
--low-priorityUse LOW_PRIORITY when loading the table. 
--no-defaultsRead no option files 
--password[=password]Password to use when connecting to server 
--pipeOn Windows, connect to server using named pipe 
--plugin-dir=pathDirectory where plugins are installed5.6.2
--port=port_numTCP/IP port number to use for connection 
--print-defaultsPrint defaults 
--protocol=typeConnection protocol to use 
--replaceThe --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values 
--secure-authDo not send passwords to the server in old (pre-4.1.1) format5.6.17
--shared-memory-base-name=nameThe name of shared memory to use for shared-memory connections 
--silentProduce output only when errors occur 
--socket=pathFor connections to localhost, the Unix socket file to use 
--sslEnable SSL for connection 
--ssl-ca=file_namePath of file that contains list of trusted SSL CAs 
--ssl-capath=dir_namePath of directory that contains trusted SSL CA certificates in PEM format 
--ssl-cert=file_namePath of file that contains X509 certificate in PEM format 
--ssl-cipher=cipher_listList of permitted ciphers to use for SSL encryption 
--ssl-crl=file_namePath of file that contains certificate revocation lists5.6.3
--ssl-crlpath=dir_namePath of directory that contains certificate revocation list files5.6.3
--ssl-key=file_namePath of file that contains X509 key in PEM format 
--ssl-verify-server-certVerify server Common Name value in its certificate against host name used when connecting to server 
--use-threads=#Number of threads for parallel file-loading 
--user=user_name,MySQL user name to use when connecting to server 
--verboseVerbose mode 
--versionDisplay 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 |
+------+---------------+