mysql5.7備份數據提示--secure-file-priv選項問題的處理方法
發表時間:2023-07-11 來源:明輝站整理相關軟件相關文章人氣:
[摘要]mysql可使用 into outfile 參數把表中數據導出到csv,例如可用以下命令把user表的數據導出到user.csvselect * from user into outfile /tm...
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。
參數說明:
into outfile ‘導出的目錄和文件名’
指定導出的目錄和文件名
fields terminated by ‘字段間分隔符’
定義字段間的分隔符
optionally enclosed by ‘字段包圍符’
定義包圍字段的字符(數值型字段無效)
lines terminated by ‘行間分隔符’
定義每行的分隔符
問題分析
以上命令在mysql5.6下運行沒有問題,但在mysql5.7下運行則出現了以下錯誤。
ERROR 1290 (HY000): The 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)
修改后再次執行,成功導出。
';
執行后,user表的數據會導出到/tmp/user.csv。
參數說明:
into outfile ‘導出的目錄和文件名’
指定導出的目錄和文件名
fields terminated by ‘字段間分隔符’
定義字段間的分隔符
optionally enclosed by ‘字段包圍符’
定義包圍字段的字符(數值型字段無效)
lines terminated by ‘行間分隔符’
定義每行的分隔符
問題分析
以上命令在mysql5.6下運行沒有問題,但在mysql5.7下運行則出現了以下錯誤。
ERROR 1290 (HY000): The 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)
以上就是mysql5.7導出數據提示--secure-file-priv選項問題的解決方法的詳細內容,更多請關注php中文網其它相關文章!
學習教程快速掌握從入門到精通的SQL知識。