select * from user into outfile /tmp/user.csv fields terminated by , optionally enclosed by lines terminated by /r/n
執行后,user表的數據會導出到/tmp/user.csv。
參數說明:into outfile ‘導出的目錄和文件名’
指定導出的目錄和文件名
fields terminated by ‘字段間分隔符’
定義字段間的分隔符
optionally enclosed by ‘字段包圍符’
定義包圍字段的字符(數值型字段無效)
lines terminated by ‘行間分隔符’
定義每行的分隔符
以上命令在mysql5.6下運行沒有問題,但在mysql5.7下運行則出現了以下錯誤。
ERROR 1290 (HY000): The html' target='_blank'>MySQL server is running with the --secure-file-priv option so it cannot execute this statement
查看官方文檔,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 的值,默認為NULL,表示限制不能導入導出。
mysql show global variables like %secure_file_priv% +------------------+-------+| Variable_name | Value |+------------------+-------+| secure_file_priv | NULL |+------------------+-------+1 row in set (0.00 sec)
因為 secure_file_priv 參數是只讀參數,不能使用set global命令修改。
mysql set global secure_file_priv= ERROR 1238 (HY000): Variable secure_file_priv is a read only variable解決方法
打開my.cnf 或 my.ini,加入以下語句后重啟mysql。
secure_file_priv=
查看secure_file_priv修改后的值
mysql show global variables like %secure_file_priv% +------------------+-------+| Variable_name | Value |+------------------+-------+| secure_file_priv | |+------------------+-------+1 row in set (0.00 sec)
修改后再次執行,成功導出。
mysql select * from user into outfile /tmp/user.csv fields terminated by , optionally enclosed by lines terminated by /r/n Query OK, 15 rows affected (0.00 sec)
mysql可使用 into outfile 參數把表中數據導出到csv,例如可用以下命令把user表的數據導出到user.csv
select * from user into outfile /tmp/user.csv fields terminated by , optionally enclosed by lines terminated by /r/n
執行后,user表的數據會導出到/tmp/user.csv。
本文講解了mysql5.7導出數據提示--secure-file-priv選項問題的解決方法,更多相關內容請關注php 。
相關推薦:
php 利用debug_backtrace方法跟蹤代碼調用
mysql在終端執行sql并把結果寫入文件的方法
php 基于redis使用令牌桶算法實現流量控制
以上就是mysql secure-file-priv選項問題的解決方法的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答