数据导出
作用:把表记录存储到系统文件里
格式1
mysql> select命令 into outfile “目录名/文件” ; //文件名不需要提前建立,使用默认分隔符
格式2
mysql> select命令 into outfile “目录名/文件”
fields terminated by “分隔符”;
格式3
mysql> select命令 into outfile “目录名/文件”
fields terminated by “分隔符” lines terminated by “分隔符”;
mysql> select * from db1.user into outfile “/root/user1.txt”; //出错,导出只能导出到secure-file目录
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
mysql> show variables like “secure_file_priv”;
±-----------------±----------------------+
| Variable_name | Value |
±-----------------±----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
±-----------------±----------------------+
mysql> select * from db1.user into outfile “/var/lib/mysql-files/user1.txt”;
Query OK, 21 rows affected (0.00 sec)
可以手动修改secure-file目录
]# vim /etc/my.cnf
[mysqld]
secure_file_priv="/myload“
:wq
]# systemctl restart mysqld
mysql> show variables like “secure_file_priv”; 查看

本文介绍了MySQL数据导出的作用,即把表记录存储到系统文件里,并给出三种导出格式。同时指出导出时只能导出到secure-file目录,通过示例展示了错误情况及查看该目录的方法,还说明了可手动修改secure-file目录并重启服务。
2859

被折叠的 条评论
为什么被折叠?



