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, see Section 4.2.6, “Using Option Files”.

Table 4.9 mysqlimport Options

FormatOption FileDescriptionIntroduced
--bind-address=ip_addressbind-addressUse the specified network interface to connect to the MySQL Server 
--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 the program exits 
--debug-infodebug-infoPrint debugging information, memory and CPU statistics when the program exits 
--default-auth=plugindefault-auth=pluginThe authentication plugin to use5.6.2
--default-character-set=charset_namedefault-character-setSet the default character set 
--defaults-extra-file=file_name Read option file in addition to the usual option files 
--defaults-file=file_name Read only the given 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 the MySQL server on the 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 
--login-path=name Read login path options from .mylogin.cnf5.6.6
--low-prioritylow-priorityUse LOW_PRIORITY when loading the table. 
--no-defaults Do not read any option files 
--password[=password]passwordThe password to use when connecting to the server 
--pipe On Windows, connect to server using a named pipe 
--plugin-dir=pathplugin-dir=pathThe directory where plugins are located5.6.2
--port=port_numportThe TCP/IP port number to use for the connection 
--print-defaults Print defaults 
--protocol=typeprotocolThe connection protocol to use 
--replacereplaceThe --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values 
--secure-authsecure-authDo not send passwords to the server in old (pre-4.1.1) format5.6.17
--silentsilentProduce output only when errors occur 
--socket=pathsocketFor connections to localhost, the Unix socket file to use 
--ssl Enable 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-crl=file_namessl-crlPath of file that contains certificate revocation lists5.6.3
--ssl-crlpath=dir_namessl-crlpathPath of directory that contains certificate revocation list files5.6.3
--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 the server 
--use-threads=#use-threadsThe number 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 |
+------+---------------+