1. mysql可以直接load data
用法:LOAD DATA [LOW_PRIORITY] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE tbl_name
<small>默认字段分割符:\t, 默认行分隔符:\n </small>
<small>示例:load data infile "file.txt" into table comments character set utf8 (id,comment);</small>
<small>如果出现错误:</small>
<pre>The MySQL server is running with the --secure-file-priv option so it cannot execute this statement</pre>
执行:
<pre> show variables like '%secure%';
+--------------------------+-----------------------+
| Variable_name | Value |
+--------------------------+-----------------------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | /var/lib/mysql-files/ |
+--------------------------+-----------------------+</pre>
<small>将文件移动到/var/lib/mysql-files/,指定文件位置/var/lib/mysql-files/file_name.txt,重新执行 。具体用法</small>