Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 39.4Mb
PDF (A4) - 39.4Mb
PDF (RPM) - 38.7Mb
HTML Download (TGZ) - 11.1Mb
HTML Download (Zip) - 11.1Mb
HTML Download (RPM) - 9.8Mb
Man Pages (TGZ) - 213.4Kb
Man Pages (Zip) - 322.6Kb
Info (Gzip) - 3.6Mb
Info (Zip) - 3.6Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  mysqlimport — A Data Import Program

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.14 mysqlimport Options

Format Description Introduced Deprecated
--bind-address Use specified network interface to connect to MySQL Server
--columns This option takes a comma-separated list of column names as its value
--compress Compress all information sent between client and server
--debug Write debugging log
--debug-check Print debugging information when program exits
--debug-info Print debugging information, memory, and CPU statistics when program exits
--default-auth Authentication plugin to use
--default-character-set Specify default character set
--defaults-extra-file Read named option file in addition to usual option files
--defaults-file Read only named option file
--defaults-group-suffix Option group suffix value
--delete Empty the table before importing the text file
--enable-cleartext-plugin Enable cleartext authentication plugin 5.7.10
--fields-enclosed-by This option has the same meaning as the corresponding clause for LOAD DATA INFILE
--fields-escaped-by This option has the same meaning as the corresponding clause for LOAD DATA INFILE
--fields-optionally-enclosed-by This option has the same meaning as the corresponding clause for LOAD DATA INFILE
--fields-terminated-by This option has the same meaning as the corresponding clause for LOAD DATA INFILE
--force Continue even if an SQL error occurs
--get-server-public-key Request RSA public key from server 5.7.23
--help Display help message and exit
--host Connect to MySQL server on given host
--ignore See the description for the --replace option
--ignore-lines Ignore the first N lines of the data file
--lines-terminated-by This option has the same meaning as the corresponding clause for LOAD DATA INFILE
--local Read input files locally from the client host
--lock-tables Lock all tables for writing before processing any text files
--login-path Read login path options from .mylogin.cnf
--low-priority Use LOW_PRIORITY when loading the table.
--no-defaults Read no option files
--password Password to use when connecting to server
--pipe On Windows, connect to server using named pipe
--plugin-dir Directory where plugins are installed
--port TCP/IP port number for connection
--print-defaults Print default options
--protocol Connection protocol to use
--replace The --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values
--secure-auth Do not send passwords to server in old (pre-4.1) format 5.7.4 5.7.5
--server-public-key-path Path name to file containing RSA public key 5.7.23
--shared-memory-base-name The name of shared memory to use for shared-memory connections
--silent Produce output only when errors occur
--socket For connections to localhost, the Unix socket file to use
--ssl Enable encrypted connection
--ssl-ca File that contains list of trusted SSL Certificate Authorities
--ssl-capath Directory that contains trusted SSL Certificate Authority certificate files
--ssl-cert File that contains X.509 certificate
--ssl-cipher List of permitted ciphers for connection encryption
--ssl-crl File that contains certificate revocation lists
--ssl-crlpath Directory that contains certificate revocation list files
--ssl-key File that contains X.509 key
--ssl-mode Security state of connection to server 5.7.11
--ssl-verify-server-cert Verify host name against server certificate Common Name identity
--tls-version Protocols permitted for encrypted connections 5.7.10
--use-threads Number of threads for parallel file-loading
--user MySQL 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
100     Max Sydow
101     Count Dracula
w imptest.txt
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
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 |

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by Bill Swartz on February 2, 2011
Running mysqlimport v3.7 under Win32. Contrary to expected behavior, double quoting the textfile parameter does not cause the tool to accept directory or file names that contain whitespace.
  Posted by Paul Mars on May 23, 2012
Here's how I got mysqlimport to work on Windows:

  Posted by josé ambriz meza on December 27, 2012
En español, explicación de la importación

  Posted by yangqing yang on June 8, 2018

If you load a file in the mysql-server without using the --local option,you may get an error.
In that case,the mysql-server looks for the load file in DATADIR directory.

SO,you could use mysql-client mysqlimport whith the option --local,or put the file in the DATADIR directory.
Sign Up Login You must be logged in to post a comment.