mysql 导出CSV文件 并带表头的方法
参考官方文档http://dev.mysql.com/doc/refman/5.7/en/select-into.html
mysql>selectgame,domain,type ->intooutfile'd:\\game.csv' ->fieldsterminatedby',' ->linesterminatedby'\n' ->fromgame_listslimit10;
实例如下:
mysql>createtabletest(idint(10)notnullauto_incrementprimarykey,namevarchar(10)notnull,agetinyint(2)notnull)engine=innodbdefaultcharset=utf8;
mysql>insertintotest(`name`,`age`)values('Lee',20),('Li',30),('Wang',22),('Feng',23);
先查看一下结果
mysql>select*from(select'name','age'unionselectname,agefromtest)b; +------+-----+ |name|age| +------+-----+ |name|age| |Lee|20| |Li|30| |Wang|22| |Feng|23| +------+-----+ 5rowsinset(0.00sec)
导出CSV文件
mysql>select*intooutfile'd:\\tmp\\columns.csv'fieldsterminatedby','linesterminatedby'\n'from(select'name','age'unionselectname,agefromtest)b; QueryOK,5rowsaffected(0.00sec)
以上这篇mysql导出CSV文件并带表头的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短