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 12.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] option file groups. mysqlimport also supports the options for processing option files described at Section 4.2.3.3.1, “Command-Line Options that Affect Option-File Handling”.

Table 4.6. mysqlimport Options

FormatOption FileDescriptionIntroductionDeprecatedRemoved
--bind-address=ip_addressbind-addressUse the specified network interface to connect to the MySQL Server5.5.8  
--columns=column_listcolumnsThis option takes a comma-separated list of column names as its value   
--compresscompressCompress all information sent between the client and the 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-character-set=charset_namedefault-character-setUse charset_name as the default character set   
--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   
--low-prioritylow-priorityUse LOW_PRIORITY when loading the table.   
--password[=password]passwordThe password to use when connecting to the server   
--pipe On Windows, connect to server using a named pipe   
--port=port_numportThe TCP/IP port number to use for the connection   
--protocol=typeprotocolThe connection protocol to use   
--replacereplaceThe --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values   
--silentsilentProduce output only when errors occur   
--socket=pathsocketFor connections to localhost   
--ssl-ca=file_namessl-caThe path to a file that contains a list of trusted SSL CAs   
--ssl-capath=directory_namessl-capathThe path to a directory that contains trusted SSL CA certificates in PEM format   
--ssl-cert=file_namessl-certThe name of the SSL certificate file to use for establishing a secure connection   
--ssl-cipher=cipher_listssl-cipherA list of allowable ciphers to use for SSL encryption   
--ssl-key=file_namessl-keyThe name of the SSL key file to use for establishing a secure connection   
--ssl-verify-server-certssl-verify-server-certThe server's Common Name value in its certificate is verified against the host name used when connecting to the server   
--use-threads=#use-threadsThe number of threads for parallel file-loading   
--user=user_name,userThe MySQL user name to use when connecting to the 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 |
+------+---------------+
Copyright © 2010-2017 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout