导出mysql的表格内容到txt文件
操作流程:
$ 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)