mysql 導出CSV文件 並帶表頭的方法。本站提示廣大學習愛好者:(mysql 導出CSV文件 並帶表頭的方法)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql 導出CSV文件 並帶表頭的方法正文
參考官方文檔 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文件 並帶表頭的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持。