如何将mysql查询的结果写入文件?我只需要一些快速的东西.输出可以是CSV,XML,HTML等.
SELECT a,b,a+b FROM test_table INTO OUTFILE '/tmp/result.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
(文档在SELECT ..部分中显示INTO OUTFILE也可以正常工作,但我从未尝试过这种方式) http://dev.mysql.com/doc/refman/5.0/en/select.html
INTO OUTFILE在服务器上创建一个文件; 如果您在客户端并想要它,请执行以下操作:
mysql -u you -p -e "SELECT ..." > file_name