饿虎岗资源网 Design By www.oxmxm.com

参考官方文档 http://dev.mysql.com/doc/refman/5.7/en/select-into.html

mysql> select game,domain,type

-> into outfile 'd:\\game.csv' 
-> fields terminated by ','

-> lines terminated by '\n'

-> from game_lists limit 10;

实例如下:

mysql> create table test(id int(10) not null auto_increment primary key, name varchar(10) not null,age tinyint(2) not null)engine=innodb default charset=utf8;

mysql> insert into test(`name`,`age`) values ('Lee',20),('Li',30),('Wang',22),('Feng',23);

先查看一下结果

mysql> select * from (select 'name','age' union select name,age from test) b;
+------+-----+
| name | age |
+------+-----+
| name | age |
| Lee | 20 |
| Li  | 30 |
| Wang | 22 |
| Feng | 23 |
+------+-----+
5 rows in set (0.00 sec)

导出CSV文件

mysql> select * into outfile 'd:\\tmp\\columns.csv' fields terminated by ',' lines terminated by '\n' from (select 'name','age' union select name,age from test) b;
Query OK, 5 rows affected (0.00 sec)

以上这篇mysql 导出CSV文件 并带表头的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com