最近常需要將大表導出為csv格式,在使用select * into outfile xxx的時候,就會出現此報錯。
[Code: 1290, SQL State: HY000] The MySQL server is running with the –secure-file-priv option so it cannot execute this statement
這時候可以先檢查這個參數的值,在mysql數據庫中輸入以下命令:
show variables like ‘%secure_file_priv%’;
然后就可以看到:
默認的路徑是/var/lib/mysql-files。
如果要想修改此路徑的話,只能通過修改啟動時添加特定參數或者修改配置文件后重啟服務來實現。
-
啟動時添加特定參數。可通過mysqld -secure-file-priv=xxx來實現。
-
修改配置文件后重啟。可以在mysql配置文件中mysqld選項下添加參數**secure-file-priv來實現。
其中,如果:
secure_file_priv=null 不允許csv文件的導入導出
secure_file_priv=xxx csv文件導入導出到某路徑
secure_file_priv=/ csv文件可導入到任意路徑