您的位置:首页 > 数据库 > MySQL

将mysql执行结果按照固定格式写入文件

2014-03-24 14:05 253 查看
该脚本是先删除已经存在的文件,然后后台执行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


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 脚本 固定格式