MySQL数据库表跨域复制同步


##本地数据库导入SQL

 

#!/bin/bash

v_db_ip=127.0.0.1
v_db_port=3306
v_db_user=admin
v_db_pwd=123456

dir_root=/alidata/projects/tomcat-ins/plan_backend_server_60003/scripts
script_sql=$dir_root/sql_load_import.sql

fImport(){
        echo "exec script_db_import.sh..."

        /alidata/server/mysql/bin/mysql \
        -P$v_db_port \
        -u$v_db_user \
        -p$v_db_pwd \
        "plan_backend_server" < $script_sql
}

fImport
~      


##远程数据库生成SQL文件


v_currday=$1

v_db_ip=127.0.0.1
v_db_port=3306
v_db_user=admin
v_db_pwd=123456

dir_root=/alidata/projects/tomcat-ins/plan_backend_server_60003/scripts
script_sql=$dir_root/sql_load_import.sql


fExportAppSignIn(){
        echo "-- export table app_sign_in"
        echo "-- export table app_sign_in " >> $script_sql
        echo "DELETE FROM \`plan_backend_server\`.\`app_sign_in\` WHERE DATE_FORMAT(\`createTime\`, '%Y%m%d')='"$v_currday"';" >> $script_sql

        /alidata/server/mysql/bin/mysqldump "plan_admin" "app_sign_in" \
        --host=$v_db_ip \
        --port=$v_db_port \
        --user=$v_db_user \
        --password=$v_db_pwd \
        --no-create-db \
        --no-create-info \
        --default-character-set=utf8 \
        --set-gtid-purged=off \
        --where="DATE_FORMAT(\`createTime\`, '%Y%m%d')='"$v_currday"'" >> $script_sql

        echo "" >> $script_sql
        echo "" >> $script_sql

}

fExportAppSignIn



##main方法

#!/bin/bash


echo '1' >> /alidata/projects/tomcat-ins/plan_backend_server_60003/scripts/test.log

v_yesterday=`date -d yesterday +"%Y%m%d"`

echo $v_yesterday


cd /alidata/projects/tomcat-ins/plan_backend_server_60003/scripts

dir_root=/alidata/projects/tomcat-ins/plan_backend_server_60003/scripts
script_sql=$dir_root/sql_load_import.sql

echo "" > $script_sql

./script_db_export_wx.sh $v_yesterday
./script_db_export.sh $v_yesterday
./script_db_pro.sh $v_yesterday

./script_db_import.sh


 

你可能感兴趣的:(数据库篇)