Home >Database >Mysql Tutorial >将mysql执行结果按照固定格式写入文件_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:18:011070browse

bitsCN.com

该脚本是先删除已经存在的文件,然后后台执行SQL语句将其执行结果以一定的格式写入文件

#!/bin/bashif [ -f "/var/lib/mysql/hell.txt" ]; thenrm -f /var/lib/mysql/hell.txtecho "delete /var/lib/mysql/hell.txt" >> hell.txtfimysql -uroot -plab <<EOFuse home;select YongHuID,XueYuanID into outfile &#39;./hell.txt&#39; fields terminated by &#39;|&#39; lines terminated by &#39;/r/n&#39; from sns_home_user where YongHuID < 20;EOF
bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn