mysql查询结果写入文件

注:转自csdn zuyi532

方法1:
shell> mysql -uroot -proot -h localhost xxx库 -e " select * from xxx表 limit 1" >> out.txt
 
方法2:
#>echo "select * from xxx表 limit 1" | /usr/local/mysql/bin/mysql -h 127.0.0.1  -uroot -proot xxx库 > /home/out.txt
 
方法3:
mysql>select * from xxx表 INTO OUTFILE './xxx.txt';
 
前两种都是在系统命令行下执行

方法3需要登录到mysql并use数据库,生成的文件只能放在mysql的数据目录中,Mysql的数据目录就是存放mysql的表的目录 **/mysql/var

posted @ 2014-11-17 14:56  Beats  阅读(475)  评论(0编辑  收藏  举报