1. into outfile filename;
mysql> use world; # 使用 mysql 自带的 world 数据库
mysql> select * from country into outfile "xx\\xx.xx";
# 这样输出的结果便不会显示在命令行,而是导出到文件;
注意:windows 下路径分隔符用 \\
(windows 默认是单斜杠)。
2. The MySQL server is running with the –secure-file-priv option so it cannot execute this
MYSQL导出数据出现The MySQL server is running with the –secure-file-priv option so it cannot execute this
mysql> show variables like '%secure%';
+--------------------------+------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\ |
+--------------------------+------------------------------------------------+
也就是 sql 语句中导出的文件路径必须在变量 secure_file_priv
指定的路径下。如:
mysql> select * from country into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\country.xls";
注意,在 mysql 的配置文件 my.ini 中,能够看到对 secure_file_priv
变量的设置。