日期:2014-05-16  浏览次数:20575 次

找到两个库中不同的表的脚本
MASTER_DB_HOST="luxun"
MASTER_DB_NAME="your_database"
MASTER_DB_USER="your db user"
MASTER_DB_PSW="your password"

SLAVE_DB_HOST="localhost"
SLAVE_DB_NAME="your_database"
SLAVE_DB_USER="your db user"
SLAVE_DB_PSW="your password"

TMP_SQL_PATH="/rawsql/$MASTER_DB_NAME-difftables.sql"

mysqlshow -u $MASTER_DB_USER -p$MASTER_DB_PSW  $MASTER_DB_NAME --count -h $MASTER_DB_HOST>master
mysqlshow -u $SLAVE_DB_USER -p$SLAVE_DB_PSW  $SLAVE_DB_NAME --count -h $SLAVE_DB_HOST>slave

diff master slave|grep '<' | awk -F'|' '{print $2}' >difftables
ARGS=`cat difftables`

echo " now dump remote master mysql diff tables"
mysqldump -u$MASTER_DB_USER -p$MASTER_DB_PSW -h $MASTER_DB_HOST $MASTER_DB_NAME $ARGS  >$TMP_SQL_PATH


echo "now import difftables to slave ..."
mysql -u $SLAVE_DB_USER -p$SLAVE_DB_PSW -h $SLAVE_DB_HOST $SLAVE_DB_NAME <$TMP_SQL_PATH

echo "sync done "
mysqlshow -u $MASTER_DB_USER -p$MASTER_DB_PSW  $MASTER_DB_HOST --count -h $MASTER_DB_HOST>master
mysqlshow -u $SLAVE_DB_USER -p$SLAVE_DB_PSW  $SLAVE_DB_HOST --count -h $SLAVE_DB_HOST>slave
diff master slave

?