您的位置:首页 > 数据库 > MySQL

导出mysql的表格内容到txt文件

2017-08-30 15:18 309 查看
操作流程:

$ 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就会报错:

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: