4.5.5 mysqlimport — A Data Import Program数据导入程序

The mysqlimport client provides a command-line interface to the LOAD DATA SQL statement. mysqlimport客户端为LOAD DATA SQL语句提供了一个命令行接口。Most options to mysqlimport correspond directly to clauses of LOAD DATA syntax. mysqlimport的大多数选项直接对应于LOAD DATA语法的子句。See Section 13.2.7, “LOAD DATA Statement”.请参见第13.2.7节,“LOAD DATA语句”

Invoke mysqlimport like this:调用mysqlimport方法如下:

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. 对于命令行上命名的每个文本文件,mysqlimport从文件名中去掉任何扩展名,并使用结果来确定要将文件内容导入的表的名称。For example, files named patient.txt, patient.text, and patient all would be imported into a table named patient.例如,名为patient.txtpatient.textpatient的文件全将导入名为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. mysqlimport支持以下选项,这些选项可以在命令行上指定,也可以在选项文件的[mysqlimport][client]组中指定。For information about option files used by MySQL programs, see Section 4.2.2.2, “Using Option Files”.有关MySQL程序使用的选项文件的信息,请参阅第4.2.2.2节,“使用选项文件”

Table 4.15 mysqlimport Options表4.15 mysqlimport选项

Option Name选项名称Description描述Introduced引入版本Deprecated弃用版本
--bind-addressUse specified network interface to connect to MySQL Server使用指定的网络接口连接到MySQL Server
--columnsThis option takes a comma-separated list of column names as its value此选项采用逗号分隔的列名列表作为其值
--compressCompress all information sent between client and server压缩客户端和服务器之间发送的所有信息8.0.18
--compression-algorithmsPermitted compression algorithms for connections to server允许的服务器连接压缩算法8.0.18
--debugWrite debugging log写入调试日志
--debug-checkPrint debugging information when program exits程序退出时打印调试信息
--debug-infoPrint debugging information, memory, and CPU statistics when program exits程序退出时打印调试信息、内存和CPU统计信息
--default-authAuthentication plugin to use要使用的身份验证插件
--default-character-setSpecify default character set指定默认字符集
--defaults-extra-fileRead named option file in addition to usual option files除了读取常用选项文件外,还读取命名选项文件
--defaults-fileRead only named option file只读命名选项文件
--defaults-group-suffixOption group suffix value选项组后缀值
--deleteEmpty the table before importing the text file在导入文本文件之前清空表
--enable-cleartext-pluginEnable cleartext authentication plugin启用明文身份验证插件
--fields-enclosed-byThis option has the same meaning as the corresponding clause for LOAD DATA此选项与LOAD DATA的相应子句具有相同的含义
--fields-escaped-byThis option has the same meaning as the corresponding clause for LOAD DATA此选项与LOAD DATA的相应子句具有相同的含义
--fields-optionally-enclosed-byThis option has the same meaning as the corresponding clause for LOAD DATA此选项与LOAD DATA的相应子句具有相同的含义
--fields-terminated-byThis option has the same meaning as the corresponding clause for LOAD DATA此选项与LOAD DATA的相应子句具有相同的含义
--forceContinue even if an SQL error occurs即使发生SQL错误也要继续
--get-server-public-keyRequest RSA public key from server从服务器请求RSA公钥
--helpDisplay help message and exit显示帮助信息并退出
--hostHost on which MySQL server is locatedMySQL服务器所在的主机
--ignoreSee the description for the --replace option请参阅--replace选项的说明
--ignore-linesIgnore the first N lines of the data file忽略数据文件的前N
--lines-terminated-byThis option has the same meaning as the corresponding clause for LOAD DATA此选项与LOAD DATA的相应子句具有相同的含义
--localRead input files locally from the client host从客户端主机本地读取输入文件
--lock-tablesLock all tables for writing before processing any text files在处理任何文本文件之前锁定所有表以进行写入
--login-pathRead login path options from .mylogin.cnf从.mylogin.cnf读取登录路径选项
--low-priorityUse LOW_PRIORITY when loading the table加载表时使用LOW_PRIORITY
--no-defaultsRead no option files不读取选项文件
--passwordPassword to use when connecting to server连接到服务器时使用的密码
--pipeConnect to server using named pipe (Windows only)使用命名管道连接到服务器(仅限Windows)
--plugin-dirDirectory where plugins are installed安装插件的目录
--portTCP/IP port number for connection用于连接的TCP/IP端口号
--print-defaultsPrint default options打印默认选项
--protocolTransport protocol to use要使用的传输协议
--replaceThe --replace and --ignore options control handling of input rows that duplicate existing rows on unique key values--replace--ignore选项控制对与唯一键值上的现有行重复的输入行的处理
--server-public-key-pathPath name to file containing RSA public key包含RSA公钥的文件的路径名
--shared-memory-base-nameShared-memory name for shared-memory connections (Windows only)共享内存连接的共享内存名称(仅限Windows)
--silentProduce output only when errors occur仅在出现错误时产生输出
--socketUnix socket file or Windows named pipe to use要使用的Unix套接字文件或Windows命名管道
--ssl-caFile that contains list of trusted SSL Certificate Authorities包含受信任SSL证书颁发机构列表的文件
--ssl-capathDirectory that contains trusted SSL Certificate Authority certificate files包含受信任的SSL证书颁发机构证书文件的目录
--ssl-certFile that contains X.509 certificate包含X.509证书的文件
--ssl-cipherPermissible ciphers for connection encryption用于连接加密的允许密码
--ssl-crlFile that contains certificate revocation lists包含证书吊销列表的文件
--ssl-crlpathDirectory that contains certificate revocation-list files包含证书吊销列表文件的目录
--ssl-fips-modeWhether to enable FIPS mode on client side是否在客户端启用FIPS模式
--ssl-keyFile that contains X.509 key包含X.509密钥的文件
--ssl-modeDesired security state of connection to server与服务器连接的所需安全状态
--tls-ciphersuitesPermissible TLSv1.3 ciphersuites for encrypted connections允许用于加密连接的TLSv1.3密码套件8.0.16
--tls-versionPermissible TLS protocols for encrypted connections用于加密连接的允许TLS协议
--use-threadsNumber of threads for parallel file-loading用于并行文件加载的线程数
--userMySQL user name to use when connecting to server连接到服务器时要使用的MySQL用户名
--verboseVerbose mode详细模式
--versionDisplay version information and exit显示版本信息并退出
--zstd-compression-levelCompression level for connections to server that use zstd compression使用zstd压缩的服务器连接的压缩级别8.0.18

Here is a sample session that demonstrates use of mysqlimport:下面是一个示例会话,演示了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 |
+------+---------------+