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.txtmysql

相關文章
相關標籤/搜索