mysql 默认对导出的目录有权限限制,也就是说使用命令行进行导出的时候,需要指定目录进行操作;
mysql> select * from t1 into outfile '/tmp/t1_mysql.csv' fields terminated by ",";
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
解决方法:
1. 查询mysql 的secure_file_priv 值配置的是什么
[mysqld]
secure-file-priv=/var/lib/mysql
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql -u root
2. 使用 into outfile 开始导出:因为secure_file_priv配置的关系,所以必须导出到 /var/lib/mysql/目录下
mysql> select * from t1 into outfile '/var/lib/mysql/t1_mysql.csv' fields terminated by "," OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
3. 关键字解释:因为导出的数据会出现一些乱码或者特殊字符,所以使用以上关键字进行转义
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY ' " ' LINES TERMINATED BY '\n';
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。