mysql语法如何把查询结果导出不同格式(CSV、Excel、XML、TXT)

2024年10月07日 建站教程

如何利用mysql语法把数据库查询结果以不同格式类型导出出来?下面web建站小编给大家简单介绍一下具体实现代码!

mysql查询并导出为CSV文件

SELECT * INTO OUTFILE 'test.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM table_name;

mysql查询并导出为Excel文件

SELECT * INTO OUTFILE 'test.xls'
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM table_name;

mysql查询并导出为XML文件

SELECT * FROM table_name 
INTO OUTFILE 'test.xml'
ROWS IDENTIFIED BY '<row>';

mysql查询并导出为TXT文件

SELECT * INTO OUTFILE 'test.txt'
FROM table_name;

本文链接:http://so.lmcjl.com/news/14847/

展开阅读全文
相关内容