mysql 数据库 切表的脚本
#!/bin/sh
host=$1
port=$2
host=${host:="localhost"} #host没赋值,那么就赋值为localhost
port=${port:="3306"}
schema=$3
echo $host, $port, $schema
#sleep 15
echo "=====bre2.0 archive tables ...."
date "+%F %T"
dater=`date -d "-1 day" "+%Y%m%d"`
exe_sql="create table Mapping_event_tmp like Mapping_event; rename table Mapping_event to Mapping_event_$dater, Mapping_event_tmp to Mapping_event;"
#如果只传了schema进来, 则只修改该schema下的所有表
if [ "$schema" ]
then
echo "===="$schema
echo $exe_sql
echo $exe_sql | mysql -h $host -P $port -uusername -ppassword $schema
#如果schema没传则修改该服务器下面的所有表
else
mysql -h $host -P $port -uusername -ppassword -e "show databases like 'DMP_GDMP%';" -N | while read schema
do
echo "===="$schema
echo $exe_sql
echo $exe_sql | mysql -h $host -P $port -uusername -ppassword $schema
done
fi
host=$1
port=$2
host=${host:="localhost"} #host没赋值,那么就赋值为localhost
port=${port:="3306"}
schema=$3
echo $host, $port, $schema
#sleep 15
echo "=====bre2.0 archive tables ...."
date "+%F %T"
dater=`date -d "-1 day" "+%Y%m%d"`
exe_sql="create table Mapping_event_tmp like Mapping_event; rename table Mapping_event to Mapping_event_$dater, Mapping_event_tmp to Mapping_event;"
#如果只传了schema进来, 则只修改该schema下的所有表
if [ "$schema" ]
then
echo "===="$schema
echo $exe_sql
echo $exe_sql | mysql -h $host -P $port -uusername -ppassword $schema
#如果schema没传则修改该服务器下面的所有表
else
mysql -h $host -P $port -uusername -ppassword -e "show databases like 'DMP_GDMP%';" -N | while read schema
do
echo "===="$schema
echo $exe_sql
echo $exe_sql | mysql -h $host -P $port -uusername -ppassword $schema
done
fi
date "+%F %T"
说明 schema是数据库名字
感谢haifeng