首页 > 系统 > Linux > 正文

把mysql查询结果保存到文件的shell脚本

2019-10-26 18:40:21
字体:
来源:转载
供稿:网友

该脚本是先删除已经存在的文件,然后后台执行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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表