1. 程式人生 > >mysql load data secure-file-priv問題

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);