save mysql query results into a file
2013-06-05有时候我们需要将mysql查询结果保存下来,oracle有spool,mysql怎么将查询结果保存下来呢?
1、mysql -e参数
mysql -uroot -pwallcopper -Dmysql -e"select user,host,password from mysql.user" > user.txt
2、select into outfile
seleclt * from tables into outfile '/tmp/a.csv';
3、格式化数据
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'