shell提取msyql指定数据库下表创建语句为单文件

WBOY
发布: 2016-06-07 16:10:21
原创
1443 人浏览过

dbcn=mysql -h172.16.1.194 -uroot -p123456;db=dsp_ad_center;ii=0;ct=`$dbcn -N -e SELECT COUNT(1) FROM information_schema.TABLES AS t WHERE t.TABLE_SCHEMA = $db AND t.TABLE_TYPE = BASE TABLE ; `;mkdir -p /chenenhui/$dbwhile true;doif [ $ii -

dbcn="mysql -h172.16.1.194 -uroot -p123456";
db=dsp_ad_center;
ii=0;
ct=`$dbcn -N -e " SELECT COUNT(1)  FROM information_schema.TABLES AS t WHERE t.TABLE_SCHEMA = '$db' AND t.TABLE_TYPE = 'BASE TABLE' ; "`;
mkdir -p /chenenhui/$db

while true;
do
if [ $ii -lt $ct ]
then 
p=$ii;
let ii++;
echo p=$p 
echo ii=$ii


table_name=`$dbcn -N -e " SELECT CONCAT( t.TABLE_SCHEMA,'.',t.TABLE_NAME ) FROM information_schema.TABLES AS t  where  t.TABLE_SCHEMA = '$db' AND t.TABLE_TYPE = 'BASE TABLE' limit $p,1;"`;
echo table_name=$table_name
sleep 0;
ss=`$dbcn -N -e "SHOW CREATE TABLE  $table_name ;"`
echo -e "$ss" > /chenenhui/$db/create_table_help.tsv
`$dbcn -e " CREATE TABLE IF NOT EXISTS test.create_table_help 
		( table_name VARCHAR(1500) DEFAULT '',
		table_script VARCHAR(1500) DEFAULT '',
		xh INT AUTO_INCREMENT,PRIMARY KEY(xh)
		) CHARSET = utf8 ;
 truncate table test.create_table_help;
 LOAD DATA LOCAL INFILE '//chenenhui//$db//create_table_help.tsv' INTO TABLE  test.create_table_help CHARACTER SET utf8;"`
ss_script=`$dbcn -N -e "SELECT  concat(CASE WHEN xh = 1 THEN concat('USE ','$db;',char(10) ) ELSE table_name END ,  table_script )  FROM test.create_table_help  ;"`
echo -e "$ss_script" > /chenenhui/$db/$table_name.sql
echo ";" >> /chenenhui/$db/$table_name.sql
echo $table_name
else 
echo '_while finished';
rm /chenenhui/$db/create_table_help.tsv
`$dbcn -N -e "DROP TABLE IF  EXISTS test.create_table_help;"`
exit 0;
fi
done
登录后复制

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板