溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

非中斷業(yè)務(wù)數(shù)據(jù)庫遷移一例

發(fā)布時(shí)間:2020-08-06 13:06:27 來源:網(wǎng)絡(luò) 閱讀:2000 作者:coveringindex 欄目:MySQL數(shù)據(jù)庫

下面是某業(yè)務(wù)庫的遷移過程, 從Source Master/Slave集群遷移至Target MHA集群.

非中斷業(yè)務(wù)數(shù)據(jù)庫遷移一例


前期準(zhǔn)備, 配置數(shù)據(jù)從Source Master復(fù)制到Target Master, 即Target Master成為Source Master的Slave(若Target Master是新庫的話, 還可添加replicate-do-db=name過濾條件).


遷移開始時(shí), 在Source Master上執(zhí)行flush no_write_to_binlog tables, 和flush tables with read lock.


在Target Master上查看延時(shí)為0時(shí), 執(zhí)行flush binary logs. 然后stop slave, 和reset slave all, 清除Source Master至Target Master的復(fù)制關(guān)系. 


再后, 依次重啟各應(yīng)用節(jié)點(diǎn), 切換至Target Master新數(shù)據(jù)源.


最后在Source Master上unlock tables, 至此遷移結(jié)束.



該過程中的主角flush tables with read lock, 其含義為Closes all open tables and locks all tables for all databases with a global read lock, 即在MySQL數(shù)據(jù)庫Server層, 獲取一個(gè)全局讀鎖.


那么配角flush no_write_to_binlog tables, 其含義為Closes all open tables, forces all tables in use to be closed, 起到加速flush tables with read lock操作完成的作用.



在數(shù)據(jù)庫管理的過程中, 經(jīng)常會(huì)見到flush tables with read lock的身影.


如mysqldump備份時(shí), 通過general log會(huì)看到如下輸出.

mysqldump --login-path=mytest --default-character-set=utf8mb4 --single-transaction --routines --triggers --events --quick --force --master-data=2 --hex-blob --all-databases > full.sql


25 Query FLUSH /*!40101 LOCAL */ TABLES

25 Query FLUSH TABLES WITH READ LOCK

25 Query SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ

25 Query START TRANSACTION /*!40100 WITH CONSISTENT SNAPSHOT */

25 Query SHOW VARIABLES LIKE 'gtid\_mode'

25 Query SELECT @@GLOBAL.GTID_EXECUTED

25 Query SHOW MASTER STATUS

25 Query UNLOCK TABLES


又如xtrabackup備份時(shí), 也可見類似日志.

xtrabackup --defaults-file=/etc/my.cnf --user=abc --password=xyz --socket=/3306/mysql.sock --target-dir=./pxb_full --backup


34 QuerySET SESSION lock_wait_timeout=31536000

34 QueryFLUSH NO_WRITE_TO_BINLOG TABLES

34 QueryFLUSH TABLES WITH READ LOCK

34 QuerySHOW MASTER STATUS

34 QuerySHOW VARIABLES

34 QueryFLUSH NO_WRITE_TO_BINLOG ENGINE LOGS

34 QueryUNLOCK TABLES


MHA在線手動(dòng)切換時(shí), 也用到了flush tables with read lock, 詳見如下輸出.

masterha_master_switch --conf=/etc/masterha/app2/app2.cnf --master_state=alive --orig_master_is_new_slave

...

It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 192.168.4.33(192.168.4.33:3307)? (YES/no): yes

Wed Feb 28 21:58:41 2018 - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..

Wed Feb 28 21:58:41 2018 - [info]  ok.

...

Wed Feb 28 21:58:43 2018 - [info] Locking all tables on the orig master to reject updates from everybody (including root):

Wed Feb 28 21:58:43 2018 - [info] Executing FLUSH TABLES WITH READ LOCK..

Wed Feb 28 21:58:43 2018 - [info]  ok.

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI