mysql load data secure-file-priv問題

mysql數據庫在出於安全性考慮時,在進行load data infile和into outfile操作時,經常會出現secure-file-priv問題:
在客戶端執行:
mysql> load data infile "/tmp/file1.txt" into table t_serie_no fields terminated by ',' (transNo);
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
load data 操作:
在服務器端加local執行:
mysql> load data local infile "/tmp/file1.txt" into table t_serie_no fields terminated by ',' (transNo);
Query OK, 400000 rows affected (12.89 sec)
Records: 400000 Deleted: 0 Skipped: 0 Warnings: 0

into outfile操作:
mysql> select * from T_SCAN_RECORD_TOTAL into outfile '/tmp/T_SCAN_RECORD_TOTAL.txt';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

報錯原因可以查看secure_file_priv參數確定:
mysql> show variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set (0.00 sec)

secure_file_priv值說明:
值爲null ,表示限制mysqld 不允許導入|導出
值爲/tmp/ ,表示限制mysqld 的導入|導出只能發生在/tmp/目錄下
值沒有具體值時,表示不對mysqld 的導入|導出做限制

此參數不可以在線修改:
mysql> set global secure_file_priv='';
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable

只能加入到my.cnf中重啓服務器:
secure_file_priv=''

但是作爲線上服務器,肯定不能隨便重啓,此時可以把文件拷貝到數據庫服務器上,加上local執行:
load data local infile "/tmp/file1.txt" into table t_serie_no fields terminated by ',' (transNo);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章