目錄
- 1.GTID基本概念
- 2.GTID優(yōu)點
- 3.GTID的工作原理
- 4.GTID比傳統(tǒng)復(fù)制的優(yōu)勢
- 5.啟動的方法
- 6.GTID(一主一從)配置
- 6.1環(huán)境:
- 6.2在主庫上給從庫授權(quán):
- 6.3確保數(shù)據(jù)一致操作
- 6.4配置主庫
- 6.5配置從庫
- 6.6配置主從復(fù)制
- 7.GTID(一主倆從)
- 8.GTID(倆主一從)
- 1.最新環(huán)境
- 2.所有服務(wù)器均關(guān)閉防火墻或者放行防火墻
- 3.授權(quán)連接
- master01庫授權(quán)普通用戶
- slave進行連接
- master02授權(quán)普通用戶
- slave進行連接
- 4.分別進行配置文件修改
- 5.分別重啟
- 6.在進行GTID多主一從配置前,先引入一個概念
- 7.slave從庫以root用戶登錄進行GTID配置
- GTID(倆主一從)測試:
- slave相關(guān)命令:
- 解決問題
1.GTID基本概念
MySQL 5.6.5開始支持的,全局事務(wù)標識符(GTID(Global Transaction ID))是創(chuàng)建的唯一標識符,并與在源(主)服務(wù)器上提交的每個事務(wù)相關(guān)聯(lián)。
此標識符不但是唯一的,而且在給定復(fù)制設(shè)置中的所有服務(wù)器上都是唯一的。
所有交易和所有GTID之間都有一對一的映射關(guān)系 。
它由服務(wù)器ID以及事務(wù)ID組合而成。
這個全局事務(wù)ID不僅僅在原始服務(wù)器上唯一,在所有存在主從關(guān)系 的mysql服務(wù)器上也是唯一的。
正是因為這樣一個特性使得mysql的主從復(fù)制變得更加簡單,以及數(shù)據(jù)庫一致性更可靠。
一個GTID在一個服務(wù)器上只執(zhí)行一次,避免重復(fù)執(zhí)行導(dǎo)致數(shù)據(jù)混亂或者主從不一致。
2.GTID優(yōu)點
保證同一個事務(wù)在某slave上絕對只執(zhí)行一次,沒有執(zhí)行過的gtid事務(wù)總是會被執(zhí)行。
不用像傳統(tǒng)復(fù)制那樣保證binlog的坐標準確,因為根本不需要binlog以及坐標。
故障轉(zhuǎn)移到新的master的時候很方便,簡化了很多任務(wù)。
很容易判斷master和slave的數(shù)據(jù)是否一致。只要master上提交的事務(wù)在slave上也提交了,那么一定是一致的。
3.GTID的工作原理
1.當一個事務(wù)在主庫端執(zhí)行并提交時,產(chǎn)生GTID,一同記錄到binlog日志中。
2.binlog傳輸?shù)絪lave,并存儲到slave的relaylog后,讀取這個GTID的這個值設(shè)置gtid_next變量,即告訴Slave,下一個要執(zhí)行的GTID值。
3、sql線程從relay log中獲取GTID,然后對比slave端的binlog是否有該GTID。
4、如果有記錄,說明該GTID的事務(wù)已經(jīng)執(zhí)行,slave會忽略。
5、如果沒有記錄,slave就會執(zhí)行該GTID事務(wù),并記錄該GTID到自身的binlog,在讀取執(zhí)行事務(wù)前會先檢查其他session持有該GTID,確保不被重復(fù)執(zhí)行。
6、在解析過程中會判斷是否有主鍵,如果有就用二級索引,如果沒有就用全部掃描。
4.GTID比傳統(tǒng)復(fù)制的優(yōu)勢
1.更簡單的實現(xiàn)故障轉(zhuǎn)移(failover),不需要找log_file,log_pos
2.更簡單的搭建主從復(fù)制
3.更加安全
4.GTID是連續(xù)沒有空洞的,因此主數(shù)據(jù)庫發(fā)生沖突時,可以添加空事件的方式進行跳過
5.啟動的方法
- 方法一:如果是新搭建的服務(wù)器,直接啟動即可
- 方法二:如果是以及跑的服務(wù)器,需要重啟一下mysql server
啟動前,先關(guān)閉master的寫入,保證master端和slave端數(shù)據(jù)保持同步,所有slave需要加上skip_slave_start=1的配置參數(shù),避免啟動后還是使用之前的復(fù)制協(xié)議
6.GTID(一主一從)配置
6.1環(huán)境:
centos8.0 ip:192.168.136.239 有數(shù)據(jù) hostname:mysql01
centos8.0 ip:192.168.136.219 無數(shù)據(jù) hostname:mysql02
#二進制安裝以及mysql自啟動服務(wù)略
6.2在主庫上給從庫授權(quán):
mysql> grant replication slave on *.* to 'slave'@'192.168.136.219' identified by 'slave';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#倆服務(wù)器均關(guān)閉防火墻
[root@mysql01 ~]# systemctl stop firewalld
[root@mysql01 ~]# setenforce 0
[root@mysql02 ~]# systemctl stop firewalld
[root@mysql02 ~]# setenforce 0
從庫測試連接:
[root@mysql02 ~]# mysql -u slave -p'slave' -h192.168.136.239
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
6.3確保數(shù)據(jù)一致操作
1.對主庫進行鎖表
mysql> flush tables with read lock;
2.對主庫進行全備
[root@mysql01 ~]# mysqldump -uroot -A > /clq/all-databases-20210519.sql
3.拷貝到從庫主機上去
[root@mysql01 ~]# scp /clq/all-databases-20210519.sql root@192.168.136.219:/backup/
[root@mysql02 backup]# ll
-rw-r--r--. 1 root root 873527 5月 19 16:40 all-databases-20210519.sql
4.從庫上進行主庫的恢復(fù)
[root@mysql02 backup]# mysql -uroot -pHuawei0917@ all-databases-20210519.sql
6.4配置主庫
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /opt/data/mysql.pid
skip-name-resolve
#skip-grant-tables
log-bin = master_bin #開啟主庫日志
server-id = 10 #服務(wù)唯一標識id
gtid-mode = on #GTID模式開啟
enforce_gtid_consistency = on #強制gtid模式一致性
log-slave-updates = 1 #從庫允許更新日志,同步操作日志
binlog_format = row #binlog日志格式為行格式, 默認是mixed混合模式
skip_slave_start = 1 #跳過從庫開啟,以主庫開始開啟
#重啟
systemctl restart mysqld
6.5配置從庫
[root@mysql02 data]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /opt/data/mysql.pid
skip-name-resolve
#skip-grant-tables
gtid_mode=on
enforce_gtid_consistency=on
server-id=20
log-bin=slave_binlog #開啟從庫日志
log_slave-updates=1 #從庫允許更新
binlog_format=row #格式為行
skip-slave_start=1
#重啟
systemctl restart mysqld
查看gtid狀態(tài)情況
mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-----------+
8 rows in set (0.00 sec)
6.6配置主從復(fù)制
#從庫上root登錄配置 #help change master to 可以查看幫助文檔實例
mysql> change master to
-> master_host='192.168.136.239',
-> master_user='slave',
-> master_password='slave',
-> master_port=3306, #主庫端口
-> master_auto_position=1; #位置
#master_use_gtid = current_pos
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
Slave_IO_Running: Connecting
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
保證系統(tǒng)一致性
授權(quán)一致性
(一主一從GTID)測試:
主庫創(chuàng)建一個數(shù)據(jù)庫test,進行測試查看
從庫創(chuàng)建一個數(shù)據(jù)庫test02,進行測試查看
#主庫創(chuàng)建一個test數(shù)據(jù)庫
mysql> create database test;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
#從庫上查看同步情況
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
6 rows in set (0.00 sec)
#從庫創(chuàng)建test02庫
mysql> create database test02;
Query OK, 1 row affected (0.00 sec)
#主庫上查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys | #是沒有test02庫的
| test |
+--------------------+
5 rows in set (0.00 sec)
小結(jié):主庫上的數(shù)據(jù)操作會同步到從庫上面去,而從庫上的數(shù)據(jù)操作與主庫沒聯(lián)系
7.GTID(一主倆從)
第三臺mysql連接的話,相應(yīng)配置
第3臺mysql ,版本:centos8 ip:192.168.136.230 主機名:mysql03
[root@mysql03 ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /opt/data/mysql.pid
skip-name-resolve
#skip-grant-tables
# replication config
log-bin = master_bin
server-id = 21 #id必須與之前不同
gtid-mode = on
enforce-gtid-consistency = on
log-slave-updates = 1
binlog-format = row
skip-slave-start = 1
#查看gtid情況
mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-----------+
#由于之前只權(quán)限了一個ip,此刻在mysql01主數(shù)據(jù)庫上再授權(quán)一個ip
mysql> grant replication slave on *.* to 'slave'@'192.168.136.230' identified by 'slave';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#測試連接
[root@mysql ~]# mysql -uslave -pslave -h192.168.136.239
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.33-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
#mysql03從庫上root用戶連接進行相應(yīng)配置
[root@mysql03 ~]# mysql -uroot -p1
mysql> change master to
-> master_host='192.168.136.239', #主庫ip
-> master_user='slave', #主庫授權(quán)的普通用戶
-> master_password='slave',
-> master_port=3306, #主庫端口
-> master_auto_position=1; #位置從1開始同步
#也可以查看幫助進行配置
mysql> help change master to;
CHANGE MASTER TO
MASTER_HOST='source2.example.com',
MASTER_USER='replication',
MASTER_PASSWORD='password',
MASTER_PORT=3306,
MASTER_LOG_FILE='source2-bin.001',
MASTER_LOG_POS=4,
MASTER_CONNECT_RETRY=10;
URL: https://dev.mysql.com/doc/refman/5.7/en/change-master-to.html
#開啟
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.136.239
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master_bin.000002
Read_Master_Log_Pos: 2172
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 2387
Relay_Master_Log_File: master_bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes #顯示倆個yes則運行成功!
#mysql03查看數(shù)據(jù)庫,數(shù)據(jù)庫內(nèi)容也同步成功
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
8.GTID(倆主一從)
1.最新環(huán)境
版本 |
ip |
主機名 |
身份 |
centos8 |
192.168.136.239 |
master01 |
主庫 |
centos8 |
192.168.136.219 |
master02 |
主庫 |
centos8 |
192.168.136.230 |
slave |
從庫 |
2.所有服務(wù)器均關(guān)閉防火墻或者放行防火墻
[root@master01 ~]# systemctl stop firewalld
[root@master01 ~]# systemctl disable firewalld
[root@master02 ~]# systemctl stop firewalld
[root@master02 ~]# systemctl disable firewalld
[root@slave ~]# systemctl stop firewalld
[root@slave ~]# systemctl disable firewalld
3.授權(quán)連接
master01庫授權(quán)普通用戶
mysql> grant replication slave on *.* to 'user'@'192.168.136.%' identified by 'user';
slave進行連接
[root@slave ~]# mysql -uuser -p'user' -h192.168.136.239
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
master02授權(quán)普通用戶
mysql> grant replication slave on *.* to 'app'@'192.168.136.%' identified by 'app';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
slave進行連接
[root@slave ~]# mysql -uapp -papp -h192.168.136.219
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
4.分別進行配置文件修改
#master01主機:
[root@master01 ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /opt/data/mysql.pid
skip-name-resolve
skip-grant-tables
log-bin = master_bin
server-id = 10
gtid-mode = on
enforce-gtid-consistency = on
log-slave-updates = 1
binlog-format = row
skip-slave-start = 1
#master02主機
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /opt/data/mysql.pid
skip-name-resolve
#replication config
log-bin = master_bin
server-id = 11
gtid-mode = on
enforce-gtid-consistency = on
log-slave-updates = 1
binlog-format = row
skip-slave-start = 1
#slave主機
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /opt/data/mysql.pid
skip-name-resolve
log-bin = slave_bin
server-id = 13
gtid-mode = on
enforce-gtid-consistency = on
log-slave-updates = 1
binlog-format = row
skip-slave-start = 1
5.分別重啟
[root@master01 ~]# systemctl restart mysqld
[root@master02 ~]# systemctl restart mysqld
[root@slave ~]# systemctl restart mysqld
6.在進行GTID多主一從配置前,先引入一個概念
channel
(頻道):每一個channel都是一個獨立的slave服務(wù),都有一個IO_THREAD和SQL_THREAD,原理和普通復(fù)制一樣,只是需要在change master to語句后面使用FOR Channel來進行區(qū)分slave
在使用channel時需要將從庫的master-info-repository、relay-log-info-repository設(shè)置為table,否則會報錯。
將信息存儲庫設(shè)置為table格式
方式一(mysql內(nèi)設(shè)置):
set global master_info_repository='table';
set global relay_log_info_repository='table';
方式二(/etc/my.cnf內(nèi)設(shè)置):
3.在my.cnf中設(shè)置
master_info_repository = TABLE
relay_log_info_repository = TABLE
#檢查是否更改成功
mysql> show variables where variable_name in ('relay_log_info_repository','master_info_repository');
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| master_info_repository | TABLE |
| relay_log_info_repository | TABLE |
+---------------------------+-------+
7.slave從庫以root用戶登錄進行GTID配置
#slave從庫上配置倆個主庫GTID復(fù)制
mysql> change master to
-> master_host='192.168.136.219', #mysql02主庫ip
-> master_user='app', #mysql02主庫授權(quán)的普通用戶
-> master_password='app', #mysql02主庫授權(quán)的普通用戶密碼
-> master_port=3306, #主庫端口
-> master_auto_position=1 for channel 'master01'; #位置從1開始同步,并且第一個slave取名master01
mysql> change master to
-> master_host='192.168.136.239', #mysql01主庫ip
-> master_user='user',
-> master_password='user',
-> master_port=3306, #主庫端口
-> master_auto_position=1 for channel 'master02'; #位置從1開始同步,并且第一個slave取名master01
#查看倆個slave狀態(tài)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.136.219
Master_User: app
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: slave02-relay-bin-master1.000001
Relay_Log_Pos: 4
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: No #都是關(guān)閉的
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 0
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: b4326a77-0a31-11ec-a991-000c298d3571:1-2,
d68b404d-0a35-11ec-9df1-000c29581959:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name: master1
Master_TLS_Version:
*************************** 2. row ***************************
Slave_IO_State:
Master_Host: 192.168.136.239
Master_User: user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: slave02-relay-bin-master2.000001
Relay_Log_Pos: 4
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 0
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: b4326a77-0a31-11ec-a991-000c298d3571:1-2,
d68b404d-0a35-11ec-9df1-000c29581959:1
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name: master2
Master_TLS_Version:
2 rows in set (0.00 sec)
#開啟倆個slave
mysql> start slave;
#再次查看狀態(tài)
GTID(倆主一從)測試:
#master01主庫創(chuàng)建一個test數(shù)據(jù)庫
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
#master02主庫上查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys | #沒有內(nèi)容
+--------------------+
4 rows in set (0.00 sec)
#slave從庫查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test | #已經(jīng)同步了test庫
+--------------------+
5 rows in set (0.00 sec)
#mysql02主庫創(chuàng)建一個RHCA數(shù)據(jù)庫
mysql> create database RHCA;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| RHCA |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
#slave從庫
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| RHCA |
| mysql |
| performance_schema |
| sys | #有了mysql01主庫的test庫和mysql02的RHCA的庫
| test |
+--------------------+
6 rows in set (0.00 sec)
slave相關(guān)命令:
show slave status; //查看全部slave狀態(tài)
show slave status for channel ‘naem'; //查看單個slave狀態(tài)
reset slave; #重置全部slave
reset slave for channel ‘master1'; #重置單個slave
stop slave for channel ‘master1'; #暫停單個slave
start slave for channel ‘master1'; #開啟單個slave
雖然我在做的過程沒有遇到錯誤,但是下面這個是最最容易出現(xiàn)的錯誤
配置完開啟slave出現(xiàn)報錯
mysql> start slave;
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
解決問題
由于mysql.slave_relay_log_info表中保留了以前的復(fù)制信息,導(dǎo)致新從庫啟動時無法找到對應(yīng)文件,那么我們清理掉該表中的記錄即可
mysql> reset slave;
Query OK, 0 rows affected (0.00 sec)
以上就是MySQL示例DTID主從原理解析的詳細內(nèi)容,更多關(guān)于MySQL示例DTID主從原理的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:- Mysql主從同步的實現(xiàn)原理
- 解讀mysql主從配置及其原理分析(Master-Slave)
- Mysql主從復(fù)制作用和工作原理詳解
- MySQL主從原理及配置詳解
- MySQL主從同步原理介紹
- MySQL 主從復(fù)制原理與實踐詳解