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、当导出命令中不包含字段引用符时,数据中含有转义字符本身和字段分割符的字符需要被转义 。
推荐阅读
- MySQL还能实现分布式锁?
- 运维新人如何快速管理服务器
- 粉丝怎么做好吃?
- 常用的10种MySQL函数,数据处理一定用得上
- Index MySQL查询合理使用索引:别让你的数据库负重前行
- MySQL底层的存储结构
- MySQL分组查询后如何获取每组的前N条数据,你会吗?
- 5大常用MySQL客户端工具,入门数据库必备收藏
- MySQL递归查询上下级菜单
- 这些 MySQL 调优配置,你都知道吗?
