把mysql查询结果保存到文件的shell脚本
程序员文章站
2023-11-25 13:52:46
该脚本是先删除已经存在的文件,然后后台执行sql语句将其执行结果以一定的格式写入文件
复制代码 代码如下:#!/bin/bashif [ -f "/var/lib/mys...
该脚本是先删除已经存在的文件,然后后台执行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
上一篇: Pytorch自己加载单通道图片用作数据集训练的实例
下一篇: Python实现点云投影到平面显示