Mysql之outfile

1、outfile是将检索到的数据,保存到服务器的文件内:
格式:select * into outfile "文件地址"

示例:

mysql> select * into outfile 'f:/mysql/test/one' from teacher_class;

2、文件是自动创建的。

生成的文件格式:

默认的,采用行来区分记录,而采用tab制表符,来区分字段。

原始表:

Mysql之outfile_第1张图片

生成后的表:

Mysql之outfile_第2张图片

3、而为了满足某种特别的需求,会采用不同的分割方式。支持,在导出数据时,设置记录,与字段的分隔符。通过如下的选项:

fields:设置字段选项    Lines:设置行选项(记录选项)

字段:field terminated by '\t'

记录:lines terminated by '\n' starting by ''(每一行开始是空字符串);

select * into outfile 'f:/mysql/test/two' fields terminated by ',' lines terminated by '\n' starting by 'start:'  from teacher_class;

原始表:

Mysql之outfile_第3张图片

生成文件后的表

Mysql之outfile_第4张图片


也可以设置字段被特殊符号包裹:

select * into outfile 'f:/mysql/test/third' fields terminated by ',' enclosed by 'x' lines terminated by '\n' starting by 'start:'  from teacher_class;

Mysql之outfile_第5张图片


注:常规的,所有的记录,应该通过行来显示,例外是保存二进制数据:

Blob binary

使用into dumpfile

 select * into dumpfile 'f:/mysql/test/six' from teacher_class limit 1;

你可能感兴趣的:(mysql)