mysql导出数据select..into outfile..(导出目录、文件格式)

文章目录

          • 步骤1:查看my.ini文件中secure-file-priv的值
          • 步骤2:导出数据
          • 步骤3:指定文件格式
          • 步骤4:取消导出目录限制

步骤1:查看my.ini文件中secure-file-priv的值

mysql对数据导出的目录做了限制,默认导出默认必须和secure-file-priv一致。
mysql导出数据select..into outfile..(导出目录、文件格式)_第1张图片
mysql导出数据select..into outfile..(导出目录、文件格式)_第2张图片
所以,mysql默认导出目录就是

C:/ProgramData/MySQL/MySQL Server 8.0/Uploads
步骤2:导出数据

把category表中的记录导出到cate.txt文件中
导出脚本如下:

select*from category into outfile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/cate.txt';

这个文件路径必须和步骤一中的目录一致
文件导出好了,但用记事本打开,格式有点乱,所以需要指定下格式
mysql导出数据select..into outfile..(导出目录、文件格式)_第3张图片

步骤3:指定文件格式

指定字段之间用逗号分隔,每行记录尾部换行

select*from category into outfile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/cate.txt'
fields terminated by ','
lines terminated by '\r\n';

mysql导出数据select..into outfile..(导出目录、文件格式)_第4张图片

步骤4:取消导出目录限制

将secure-file-priv的值修改一下就可以了
(把原来的值注释掉,方便以后有需要的时候再修改回来)

secure-file-priv=""

mysql导出数据select..into outfile..(导出目录、文件格式)_第5张图片
下面我就可以把表记录导到任意目录下了。我这里导到D盘

select*from category into outfile 'D:/cate.txt'
fields terminated by ','
lines terminated by '\r\n';

mysql导出数据select..into outfile..(导出目录、文件格式)_第6张图片

你可能感兴趣的:(mysql)