環境:ubuntu14.04+mysql 5.5.61
1、登入mysql,檢視secure-file-priv相關屬性配置
mysql> show variables like '%secure%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| secure_auth | ON |
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
2 rows in set (0.00 sec)
保證secure_auth為ON狀态,如果為OFF,修改mysqld配置
新增secure_auth和secure_file_priv屬性如下
secure_file_priv = /var/lib/mysql-files/
secure-auth=1
2、重新開機mysql服務,再次查詢,保證兩個狀态後,将csv檔案cp到secure_file_priv目錄下,也可以配置其他目錄,但是需要保證目錄及檔案所屬使用者為mysql,不然報錯如下:
ERROR 29 (HY000): File '/mnt/dependences/tags.csv' not found (Errcode: 13)
上面的問題主要是權限引起,建議将相關的csv檔案拷貝至指定目錄即可
3、具體導入指令:
mysql> show tables;
+---------------------------------+
| Tables_in_dependences |
+---------------------------------+
| dependencies |
| projects |
| projects_with_repository_fields |
| repositories |
| repository_dependencies |
| tags |
| versions |
+---------------------------------+
7 rows in set (0.00 sec)
mysql>
mysql> load data infile '/var/lib/mysql-files/projects-1.2.0-2018-03-12.csv'
-> into table projects character set utf8
-> fields terminated by ',' optionally enclosed by '"' escaped by '"'
-> lines terminated by '\n';
Query OK, 2556270 rows affected, 65535 warnings (25.92 sec)
Records: 2556270 Deleted: 0 Skipped: 0 Warnings: 725292
注意最後一行 為\n 而不是 \r\n,不然可能會出現隻導入了表頭無資料,具體情況具體對待。至此,導入完畢,完後設計表結構,建立所需的索引等。