mysql_select按照指定的格式输出到文件

setup1:
生成需要查询的表名文件:
select TABLE_NAME  from TABLES where TABLE_SCHEMA='test' and TABLE_NAME like 'cust_biz%' into outfile '/tmp/tab.txt'
setup2:
编写shell,从库里查询相关的数据,以自定义的格式输出到一个文件:
[root@gsyftest ~]# cat test.sh
#!/bin/sh
rm -rf /tmp/cst/*
dbuser=root
dbpwd=111222
#DBIP=127.0.0.1
while read  new_tab
do
mysql -N -u$dbuser -p$dbpwd -P3306 -e "use custmis;SELECT * into outfile '/tmp/cst/$new_tab.txt'  FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' FROM $new_tab;"
done < /tmp/tab.txt

你可能感兴趣的:(mysql_select按照指定的格式输出到文件)