嘗試使用下列指令將MySQL 腳本結果匯出到文字檔案時INTO OUTFILE,您可能會遇到以下錯誤:
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> SELECT @@GLOBAL.secure_file_priv;
寫入允許的目錄:
寫入允許的目錄:mysql> SELECT * FROM train INTO OUTFILE '/var/lib/mysql-files/test.csv' FIELDS TERMINATED BY ',';
識別允許寫入目錄:
mysql> SELECT @@GLOBAL.secure_file_priv;
NULL 值:
如果結果為NULL,則建立~/.my.cnf 檔案:
$ vi ~/.my.cnf [mysqld_safe] [mysqld] secure_file_priv="/Users/russian_spy/"
非NULL 值:
修改/etc/my. cnf 檔案:
[mysqld] secure_file_priv="/Users/russian_spy/"
重新啟動MySQL並驗證:
mysql> SELECT @@GLOBAL.secure_file_priv;
將表格匯出到 CSV 檔案:
mysql> SELECT * FROM train INTO OUTFILE '/Users/russian_spy/test.csv' FIELDS TERMINATED BY ',';
以上是如何解決 MySQL 錯誤 1290 (HY000) --secure-file-priv 問題?的詳細內容。更多資訊請關注PHP中文網其他相關文章!