導出mysql的表格內容到txt文件

操做流程:mysql

$ mysql -uroot -p
mysql> use foo;
mysql> select * from userinfo into outfile '/var/lib/mysql-files/uc3dp_v1.0_userinfo.txt' fields terminated by ', ' lines terminated by '\n';

注意:上面命令中的路徑不能夠隨意亂指定,如改爲/tmp/uc3dp_v1.0_userinfo.txt就會報錯: sql

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

 緣由是mysql設置了安全措施,必須將文件輸出到其指定目錄才行。能夠經過以下命令查看系統設置的默認目錄:安全

mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.01 sec)
相關文章
相關標籤/搜索