mysql 导出CSV文件 并带表头的方法
程序员文章站
2023-12-29 10:40:34
参考官方文档
mysql> select game,domain,type
-> into outfile 'd:\\game.csv'...
参考官方文档
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文件 并带表头的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。