The mysqlimport utility is a bulk loader for reading the contents of text files into existing tables. It functions as a command-line interface to the LOAD DATA SQL statement and is an efficient way to enter rows into tables.
mysqlimport reads data files only. It does not read SQL-format dump files produced by mysqldump. Use mysql to read such files instead.
mysqlimport [options] db_name file_name ...
The db_name argument specifies the database that contains the tables into which you want to load data. The tables to load are determined from the filename arguments. For each filename, any extension from the first period in the name is stripped off and the remaining basename is used as the name of the table into which the file should be loaded. For example, mysqlimport will load the contents of a file named president.txt into the president table.
The --character-sets-dir and --default-character-set options were added as of MySQL 3.23.21 and 3.23.41, respectively. As of MySQL 4, mysqlimport also supports the standard SSL options.
Options Specific to mysqlimport
The following options control how mysqlimport processes input files. The next section, "Data Format Options for mysqlimport," describes options that can be used to indicate the format of the data in the input files.
List the columns in the table to which columns in the data file correspond. Values in input rows will be loaded into the named columns, and other columns will be set to their default values. col_list is a list of one or more column names separated by commas. This option was introduced in MySQL 3.23.17.
--delete, -d (boolean)
Empty each table before loading any data into it.
--force, -f (boolean)
Continue loading rows even if errors occur.
When an input row contains a value for a unique key that already exists in the table, keep the existing row and discard the input row. The --ignore and --replace options are mutually exclusive.
Ignore the first n lines of the data file. This can be used to skip an initial row of column labels, for example. This option was introduced in MySQL 4.0.2.
--local, -L (boolean)
By default, mysqlimport lets the server read the data file, which means that the file must be located on the server host and that you must have the FILE privilege. Specifying the --local option tells mysqlimport to read the data file itself and send it to the server. This is slower but works when you're running mysqlimport on a different machine than the server host, as well as on the server host even if you don't have the FILE privilege.
The --local option was introduced in MySQL 3.22.15. As of MySQL 3.23.49, it will be ineffective if the server has been configured to disallow use of LOAD DATA LOCAL.
--lock-tables, -l (boolean)
Lock each table before loading data into it.
Use the LOW_PRIORITY scheduling modifier to load data into the table. This option was introduced in MySQL 3.22.27.
--replace, -r (boolean)
When an input row contains a value for a unique key that already exists in the table, replace the existing row with the input row. The --ignore and --replace options are mutually exclusive.
Data Format Options for mysqlimport
By default, mysqlimport assumes that data files contain newline-terminated lines consisting of tab-separated values. The expected format can be altered using the following options. You may need to enclose the option value in appropriate quoting characters. These options are analogous to the data format options for the LOAD DATA statement. See the entry for LOAD DATA in Appendix D.
Specifies that column values are enclosed within the given character, usually a quote character. By default, values are assumed not to be enclosed by any character. This option precludes the use of --fields-optionally-enclosed-by.
Specifies the escape character used to escape special characters. The default is no escape character.
Specifies that column values can be enclosed within the given character, usually a quote character. This option precludes the use of --fields-enclosed-by.
Specifies the character or characters that separate column values. By default, values are assumed to be separated by tab characters.
Specifies the character or characters that terminate input lines. By default, lines are assumed to be terminated by newline characters.