ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot ···
阿新 • • 發佈:2018-12-02
MySQL報錯:ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
1.報錯
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
2.原因
什麼是secure-file-priv
,按照字面意思,就是安全的檔案許可權(pri
-> privileges
),那麼,這個secure-file-priv
又是什麼玩意兒呢?檢視mysql referman,如下:
This option sets the secure_file_priv system variable, which is used to limit the effect of data
import and export operations, such as those performed by the LOAD DATA and SELECT … INTO
OUTFILE statements and the LOAD_FILE() function.
【譯:這個選項設定系統變數: secure_file_priv
,這個變數被用於限制資料匯入的匯出操作,諸如執行LOAD DATA
以及SELECT ... INTO OUTFILE
操作以及LOAD_FILE()
函式。 】
那麼這個secure_file_priv
可以設定的值有哪些呢?其有三個值可以配置,如下:
- If empty, the variable has no effect. This is not a secure setting. 【如果此配置項值為空,則表示沒有安全設定】
- If set to the name of a directory, the server limits import and export operations to work only with files in that directory. The directory must exist; the server will not create it.
- If set to NULL, the server disables import and export operations. This value is permitted as of MySQL 5.7.6
檢視mysql的該變數值,如下:
mysql> show variables like '%secure_file_priv%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set, 1 warning (0.00 sec)
根據上述的NULL
值,可以看到是不允許匯出(入)到檔案。
3.解決辦法
在配置檔案中,設定secure-file-priv
為某個路徑即可,如下:
mysql> show variables like '%secure_file_priv%';
+------------------+--------------------------------------------------+
| Variable_name | Value |
+------------------+--------------------------------------------------+
| secure_file_priv | D:\Program Files\MySQL\MySQL Server 5.7\outfile\ |
+------------------+--------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
4. 結果
再次執行上述的SQL,如下:
mysql> select * from student into outfile 'D:/Program Files/MySQL/MySQL Server 5.7/outfile/student.csv';
Query OK, 2 rows affected (0.00 sec)
檢視執行結果如下: