1. 程式人生 > 其它 >MySQL資料匯出時出現如下錯誤: ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

MySQL資料匯出時出現如下錯誤: ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

mysql> select * from db3.usertab into outfile "/mysqldata/user2.txt";
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

解決辦法:

首先:
用以下mysql語句 檢視secure_file_priv 對應的值:

mysql> show global variables like '%secure_file_priv%';
+------------------+-----------------------+


| Variable_name | Value |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.00 sec)

按value對應的路徑匯出即可解決

mysql> select * from db3.usertab into outfile "/var/lib/mysql-files/user2.txt";
Query OK, 47 rows affected (0.00 sec)

說明講解:

檢視 secure_file_priv 的值,預設為NULL,表示限制不能匯入匯出。

檢視官方文件,secure_file_priv引數用於限制LOAD DATA, SELECT …OUTFILE, LOAD_FILE()傳到哪個指定目錄。

secure_file_priv 為 NULL 時,表示限制mysqld不允許匯入或匯出。
secure_file_priv 為 /tmp 時,表示限制mysqld只能在/tmp目錄中執行匯入匯出,其他目錄不能執行。
secure_file_priv 沒有值時,表示不限制mysqld在任意目錄的匯入匯出。
又因為 secure_file_priv 引數是隻讀引數,不能使用set global命令修改。

更改配置檔案

開啟my.cnf或my.ini,加入以下語句後重啟mysql。

secure_file_priv=''