新聞中心
使用mysqldump備份本地數(shù)據(jù)庫,然后通過AWS Data Pipeline或自定義腳本將數(shù)據(jù)導入到RDS for MySQL中。
本地兩個MySQL數(shù)據(jù)庫同步和本地MySQL遷移到RDS for MySQL是兩個不同的問題,我將分別為您詳細介紹。

渭城ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
本地兩個MySQL數(shù)據(jù)庫同步
1、使用主從復制實現(xiàn)同步
主從復制是MySQL中最常見的同步方式,通過在主庫上記錄數(shù)據(jù)變更并傳輸?shù)綇膸?,從而實現(xiàn)數(shù)據(jù)的同步。
步驟如下:
配置主庫:編輯主庫的my.cnf文件,添加以下內(nèi)容:
[mysqld] serverid=1 logbin=mysqlbin binlogdodb=需要同步的數(shù)據(jù)庫名
重啟MySQL服務。
創(chuàng)建用于同步的用戶并授權(quán):
CREATE USER '同步用戶'@'%' IDENTIFIED BY '密碼'; GRANT REPLICATION SLAVE ON *.* TO '同步用戶'@'%';
獲取主庫的二進制日志文件名和位置:
SHOW MASTER STATUS;
記下File和Position的值。
配置從庫:編輯從庫的my.cnf文件,添加以下內(nèi)容:
[mysqld] serverid=2 relaylog=relaybin
重啟MySQL服務。
在從庫上執(zhí)行以下命令,配置從庫連接主庫:
CHANGE MASTER TO MASTER_HOST='主庫IP', MASTER_USER='同步用戶', MASTER_PASSWORD='密碼', MASTER_LOG_FILE='主庫上獲取的文件名', MASTER_LOG_POS=主庫上獲取的位置;
啟動從庫的同步進程:
START SLAVE;
查看從庫同步狀態(tài):
SHOW SLAVE STATUSG;
如果Slave_IO_Running和Slave_SQL_Running的值都是Yes,則表示同步成功。
2、使用第三方工具實現(xiàn)同步(如Percona XtraBackup)
Percona XtraBackup是一個免費的開源備份工具,支持InnoDB和XtraDB引擎的熱備份,可以用于實現(xiàn)MySQL數(shù)據(jù)庫的同步。
步驟如下:
安裝Percona XtraBackup,以Ubuntu為例:
sudo aptget install perconaxtrabackup24
備份主庫:執(zhí)行以下命令,將備份文件保存到指定目錄:
pxb backup targetdir=/備份目錄 /var/lib/mysql/數(shù)據(jù)庫名 > backup.log 2>&1 &
恢復備份到從庫:執(zhí)行以下命令,將備份文件恢復到從庫的數(shù)據(jù)目錄下:
rm rf /從庫數(shù)據(jù)目錄/* && xbstream restore innodbonly parallel=4 targetdir=/從庫數(shù)據(jù)目錄 /備份目錄/backup.xtrabackup >> restore.log 2>&1 & pkill HUP xbstream || true; echo "Restore completed" | mail s "Restore completed" [email protected] && sleep 5 && tail f restore.log || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore failed" [email protected] && exit 1; exit 0; pkill 9 xbstream || true; echo "Restore failed" | mail s "Restore失敗
網(wǎng)站題目:本地兩個mysql數(shù)據(jù)庫同步_本地MySQL遷移到RDSforMySQL
新聞來源:http://fisionsoft.com.cn/article/copcjsc.html


咨詢
建站咨詢
