shell脚本实现mysql查询结果保存到文件中
分享一例shell脚本,把mysql查询结果保存到文件中。
实现方法:
先删除已经存在的文件,然后后台执行sql语句将其执行结果以一定的格式写入文件。
代码:
#!/bin/bash
# www.jiaochengji.com
if [ -f "/var/lib/mysql/hell.txt" ]; then
rm -f /var/lib/mysql/hell.txt
echo "delete /var/lib/mysql/hell.txt" >> hell.txt
fi
mysql -uroot -plab <<eof
use home;
select yonghuid,xueyuanid into outfile './hell.txt' fields terminated by '|' lines terminated by '\r\n' from sns_home_user where yonghuid < 20;
eof
您可能感兴趣的文章:
shell脚本实现mysql查询结果保存到文件中
mysql备份与同步脚本
mysql纯文本格式备份的shell脚本
shell脚本:MySQL慢查询日志和错误日志按天轮询
python shell是什么
linux下mysql 5.5.8 源码编译安装
备份MySQL数据库的Shell脚本
有关mysql查询缓存的内存碎片
通过短信发送LOG归类号码发送情况的shell脚本
学习mysql的查询缓存