把mysql查询结果保存到文件的shell脚本
时间:2022-02-07 10:10:59|栏目:Shell|点击: 次
该脚本是先删除已经存在的文件,然后后台执行SQL语句将其执行结果以一定的格式写入文件
复制代码 代码如下:
#!/bin/bash
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
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
上一篇:详解Linux中两个查找命令locate和find教程
栏 目:Shell
下一篇:shell脚本操作oracle删除表空间、创建表空间、删除用户
本文地址:http://www.codeinn.net/misctech/192641.html