操做流程: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)