mysql 导出数据到txt文件
2015-11-20 14:40
501 查看
示例:
SELECT email FROM xxxxxx where email is not null and email <> '' into outfile '/mail.txt' lines terminated by '\r\n' ;
SELECT email FROM u_emails where email is not null and email <>'' and email like '%@163.com%' LIMIT 0 ,10 into outfile '/163.txt' lines terminated by ';\r\n';
SELECT email FROM u_emails where email is not null and email <>'' and email not like '%@163.com%' and email not like '%@sina.com%' and email not like '%@qq.com%' LIMIT 0 ,10 into outfile '/other.txt' lines terminated by ';\r\n';
说明:
1.导出文件目录:
修改输出文件名的目录,以便放在指定的位置。如'a.txt'可以改成'./a.txt'或'/a.txt'。
其中'./a.txt'放在c:\mysql\data目录下了,
而'/a.txt'文件则放在c:\目录下了。
select命令认为的当前目录是数据库的存放目录
2.导出数据格式
字段之间的分隔字符,转义字符,包括字符,及记录行分隔字符。列在下面:
FIELDS
TERMINATED BY '\t'
[OPTIONALLY] ENCLOSED BY ''
ESCAPED BY '\\'
LINES
TERMINATED BY '\n'
TERMINATED 表示字段分隔
[OPTIONALLY] ENCLOSED 表示字段用什么字符包括起来,
如果使用了OPTIONALLY则只有CHAR和VERCHAR被包括 ESCAPED 表示当需要转义时用什么作为转义字符
LINES TERMINATED 表示每行记录之间用什么分隔
http://www.cnblogs.com/xh831213/archive/2012/04/10/2439886.html
SELECT email FROM xxxxxx where email is not null and email <> '' into outfile '/mail.txt' lines terminated by '\r\n' ;
SELECT email FROM u_emails where email is not null and email <>'' and email like '%@163.com%' LIMIT 0 ,10 into outfile '/163.txt' lines terminated by ';\r\n';
SELECT email FROM u_emails where email is not null and email <>'' and email not like '%@163.com%' and email not like '%@sina.com%' and email not like '%@qq.com%' LIMIT 0 ,10 into outfile '/other.txt' lines terminated by ';\r\n';
说明:
1.导出文件目录:
修改输出文件名的目录,以便放在指定的位置。如'a.txt'可以改成'./a.txt'或'/a.txt'。
其中'./a.txt'放在c:\mysql\data目录下了,
而'/a.txt'文件则放在c:\目录下了。
select命令认为的当前目录是数据库的存放目录
2.导出数据格式
字段之间的分隔字符,转义字符,包括字符,及记录行分隔字符。列在下面:
FIELDS
TERMINATED BY '\t'
[OPTIONALLY] ENCLOSED BY ''
ESCAPED BY '\\'
LINES
TERMINATED BY '\n'
TERMINATED 表示字段分隔
[OPTIONALLY] ENCLOSED 表示字段用什么字符包括起来,
如果使用了OPTIONALLY则只有CHAR和VERCHAR被包括 ESCAPED 表示当需要转义时用什么作为转义字符
LINES TERMINATED 表示每行记录之间用什么分隔
http://www.cnblogs.com/xh831213/archive/2012/04/10/2439886.html
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复