做好mysql运维,必须熟练掌握备份和恢复,实战一次不行多来几次( 三 )


MySQL [t2]> select * from test into outfile '/data/mysql/outfile.txt' fields terminated by "," enclosed by '"';Query OK, 4 rows affected (0.02 sec)zj@bogon:/data/mysql$ more outfile.txt"1","a","helloworld""2","b","helloworld""3","c","helloworld""4","d","helloworld"发现第一列是数值型,如果不希望字段两边用引号引起,则语句改为:
MySQL [t2]> select * from test into outfile '/data/mysql/outfile2.txt' fields terminated by "," optionally  enclosed by '"';Query OK, 4 rows affected (0.03 sec)zj@bogon:/data/mysql$ more outfile2.txt1,"a","helloworld"2,"b","helloworld"3,"c","helloworld"4,"d","helloworld"测试转义字符,MySQL 导出数据中需要转义的字符主要包括以下 3 类:
1、转义字符本身 2、字段分隔符 3、记录分隔符
MySQL [t2]> update test set content = '\"##!aa' where  id=1;Query OK, 1 row affected (0.05 sec)Rows matched: 1  Changed: 1  Warnings: 0MySQL [t2]> select * from test into outfile '/data/mysql/outfile3.txt' fields terminated by "," optionally enclosed by '"';Query OK, 4 rows affected (0.03 sec)*******************************************zj@bogon:/data/mysql$ more outfile3.txt1,"a","\"##!aa"2,"b","helloworld"3,"c","helloworld"4,"d","helloworld"1、当导出命令中包含字段引用符时,数据中含有转义字符本身和字段引用符的字符需要被转义;
2、当导出命令中不包含字段引用符时,数据中含有转义字符本身和字段分割符的字符需要被转义 。


推荐阅读