dbaloginSource='/data/dba/mysql8/bin/mysql -uroot_dba -ppassword -h xxx '
dbaloginTarget='mysql -h127.0.0.1 -P3340 -uroot -proot '
# show databases 过滤出数据库名
dbs=`$dbaloginSource -e "show databases \G" 2> /dev/null |grep "Database:"|grep -Ev " (information_schema|mysql|sys|performance_schema)"| awk '{print $2}'`
for db in $dbs
do
# 过滤出有表名那一行
tables=`$dbaloginSource -e "use $db;show tables \G" 2> /dev/null |grep "Tables_in_$db:"| awk '{print $2}'`
$dbaloginTarget -e "create database $db;" 2> /dev/null
for table in $tables
do
# 过滤表名
create=`$dbaloginSource -e "use $db;show create table $table \G" 2> /dev/null | grep -vE "(^\*|^[[:space:]]* Table:)" | sed 's/Create Table://g' | sed 's/\`//g'`
# 日志
#sudo echo "$create;" >> /data/dba/yanhao/shell/1.log
$dbaloginTarget -e "use $db; $create;" 2> /dev/null
if [[ $? == 0 ]]
then
echo "create table $db.$table"
fi
done
done
标签:Shell,show,ip,create,db,dev,MySQL,table,null
From: https://www.cnblogs.com/tyhA-nobody/p/18354689