MySQL示例DTID主從原理解析
1.GTID基本概念
MySQL 5.6.5開(kāi)始支持的,全局事務(wù)標(biāo)識(shí)符(GTID(Global Transaction ID))是創(chuàng)建的唯一標(biāo)識(shí)符,并與在源(主)服務(wù)器上提交的每個(gè)事務(wù)相關(guān)聯(lián)。
此標(biāo)識(shí)符不但是唯一的,而且在給定復(fù)制設(shè)置中的所有服務(wù)器上都是唯一的。
所有交易和所有GTID之間都有一對(duì)一的映射關(guān)系 。
它由服務(wù)器ID以及事務(wù)ID組合而成。
這個(gè)全局事務(wù)ID不僅僅在原始服務(wù)器上唯一,在所有存在主從關(guān)系 的mysql服務(wù)器上也是唯一的。
正是因?yàn)檫@樣一個(gè)特性使得mysql的主從復(fù)制變得更加簡(jiǎn)單,以及數(shù)據(jù)庫(kù)一致性更可靠。
一個(gè)GTID在一個(gè)服務(wù)器上只執(zhí)行一次,避免重復(fù)執(zhí)行導(dǎo)致數(shù)據(jù)混亂或者主從不一致。
2.GTID優(yōu)點(diǎn)
保證同一個(gè)事務(wù)在某slave上絕對(duì)只執(zhí)行一次,沒(méi)有執(zhí)行過(guò)的gtid事務(wù)總是會(huì)被執(zhí)行。
不用像傳統(tǒng)復(fù)制那樣保證binlog的坐標(biāo)準(zhǔn)確,因?yàn)楦静恍枰猙inlog以及坐標(biāo)。
故障轉(zhuǎn)移到新的master的時(shí)候很方便,簡(jiǎn)化了很多任務(wù)。
很容易判斷master和slave的數(shù)據(jù)是否一致。只要master上提交的事務(wù)在slave上也提交了,那么一定是一致的。
3.GTID的工作原理
1.當(dāng)一個(gè)事務(wù)在主庫(kù)端執(zhí)行并提交時(shí),產(chǎn)生GTID,一同記錄到binlog日志中。
2.binlog傳輸?shù)絪lave,并存儲(chǔ)到slave的relaylog后,讀取這個(gè)GTID的這個(gè)值設(shè)置gtid_next變量,即告訴Slave,下一個(gè)要執(zhí)行的GTID值。
3、sql線程從relay log中獲取GTID,然后對(duì)比slave端的binlog是否有該GTID。
4、如果有記錄,說(shuō)明該GTID的事務(wù)已經(jīng)執(zhí)行,slave會(huì)忽略。
5、如果沒(méi)有記錄,slave就會(huì)執(zhí)行該GTID事務(wù),并記錄該GTID到自身的binlog,在讀取執(zhí)行事務(wù)前會(huì)先檢查其他session持有該GTID,確保不被重復(fù)執(zhí)行。
6、在解析過(guò)程中會(huì)判斷是否有主鍵,如果有就用二級(jí)索引,如果沒(méi)有就用全部掃描。
4.GTID比傳統(tǒng)復(fù)制的優(yōu)勢(shì)
1.更簡(jiǎn)單的實(shí)現(xiàn)故障轉(zhuǎn)移(failover),不需要找log_file,log_pos
2.更簡(jiǎn)單的搭建主從復(fù)制
3.更加安全
4.GTID是連續(xù)沒(méi)有空洞的,因此主數(shù)據(jù)庫(kù)發(fā)生沖突時(shí),可以添加空事件的方式進(jìn)行跳過(guò)
5.啟動(dòng)的方法
- 方法一:如果是新搭建的服務(wù)器,直接啟動(dòng)即可
- 方法二:如果是以及跑的服務(wù)器,需要重啟一下mysql server
啟動(dòng)前,先關(guān)閉master的寫(xiě)入,保證master端和slave端數(shù)據(jù)保持同步,所有slave需要加上skip_slave_start=1的配置參數(shù),避免啟動(dòng)后還是使用之前的復(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 無(wú)數(shù)據(jù) hostname:mysql02
#二進(jìn)制安裝以及mysql自啟動(dòng)服務(wù)略
6.2在主庫(kù)上給從庫(kù)授權(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 從庫(kù)測(cè)試連接: [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.對(duì)主庫(kù)進(jìn)行鎖表 mysql> flush tables with read lock; 2.對(duì)主庫(kù)進(jìn)行全備 [root@mysql01 ~]# mysqldump -uroot -A > /clq/all-databases-20210519.sql 3.拷貝到從庫(kù)主機(jī)上去 [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.從庫(kù)上進(jìn)行主庫(kù)的恢復(fù) [root@mysql02 backup]# mysql -uroot -pHuawei0917@ < all-databases-20210519.sql
6.4配置主庫(kù)
[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 #開(kāi)啟主庫(kù)日志 server-id = 10 #服務(wù)唯一標(biāo)識(shí)id gtid-mode = on #GTID模式開(kāi)啟 enforce_gtid_consistency = on #強(qiáng)制gtid模式一致性 log-slave-updates = 1 #從庫(kù)允許更新日志,同步操作日志 binlog_format = row #binlog日志格式為行格式, 默認(rèn)是mixed混合模式 skip_slave_start = 1 #跳過(guò)從庫(kù)開(kāi)啟,以主庫(kù)開(kāi)始開(kāi)啟 #重啟 systemctl restart mysqld
6.5配置從庫(kù)
[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 #開(kāi)啟從庫(kù)日志 log_slave-updates=1 #從庫(kù)允許更新 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ù)制
#從庫(kù)上root登錄配置 #help change master to 可以查看幫助文檔實(shí)例 mysql> change master to -> master_host='192.168.136.239', -> master_user='slave', -> master_password='slave', -> master_port=3306, #主庫(kù)端口 -> 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)測(cè)試:
主庫(kù)創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)test,進(jìn)行測(cè)試查看
從庫(kù)創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)test02,進(jìn)行測(cè)試查看
#主庫(kù)創(chuàng)建一個(gè)test數(shù)據(jù)庫(kù) mysql> create database test; mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | +--------------------+ #從庫(kù)上查看同步情況 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | +--------------------+ 6 rows in set (0.00 sec) #從庫(kù)創(chuàng)建test02庫(kù) mysql> create database test02; Query OK, 1 row affected (0.00 sec) #主庫(kù)上查看 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | #是沒(méi)有test02庫(kù)的 | test | +--------------------+ 5 rows in set (0.00 sec)
小結(jié):主庫(kù)上的數(shù)據(jù)操作會(huì)同步到從庫(kù)上面去,而從庫(kù)上的數(shù)據(jù)操作與主庫(kù)沒(méi)聯(lián)系
7.GTID(一主倆從)
第三臺(tái)mysql連接的話,相應(yīng)配置
第3臺(tái)mysql ,版本:centos8 ip:192.168.136.230 主機(jī)名: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)限了一個(gè)ip,此刻在mysql01主數(shù)據(jù)庫(kù)上再授權(quán)一個(gè)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) #測(cè)試連接 [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從庫(kù)上root用戶連接進(jìn)行相應(yīng)配置 [root@mysql03 ~]# mysql -uroot -p1 mysql> change master to -> master_host='192.168.136.239', #主庫(kù)ip -> master_user='slave', #主庫(kù)授權(quán)的普通用戶 -> master_password='slave', -> master_port=3306, #主庫(kù)端口 -> master_auto_position=1; #位置從1開(kāi)始同步 #也可以查看幫助進(jìn)行配置 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 #開(kāi)啟 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 #顯示倆個(gè)yes則運(yùn)行成功! #mysql03查看數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)內(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 | 主機(jī)名 | 身份 |
---|---|---|---|
centos8 | 192.168.136.239 | master01 | 主庫(kù) |
centos8 | 192.168.136.219 | master02 | 主庫(kù) |
centos8 | 192.168.136.230 | slave | 從庫(kù) |
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庫(kù)授權(quán)普通用戶
mysql> grant replication slave on *.* to 'user'@'192.168.136.%' identified by 'user';
slave進(jìn)行連接
[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進(jìn)行連接
[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.分別進(jìn)行配置文件修改
#master01主機(jī): [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主機(jī) [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主機(jī) [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.在進(jìn)行GTID多主一從配置前,先引入一個(gè)概念
channel
(頻道):每一個(gè)channel都是一個(gè)獨(dú)立的slave服務(wù),都有一個(gè)IO_THREAD和SQL_THREAD,原理和普通復(fù)制一樣,只是需要在change master to語(yǔ)句后面使用FOR Channel來(lái)進(jìn)行區(qū)分slave
在使用channel時(shí)需要將從庫(kù)的master-info-repository、relay-log-info-repository設(shè)置為table,否則會(huì)報(bào)錯(cuò)。
將信息存儲(chǔ)庫(kù)設(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從庫(kù)以root用戶登錄進(jìn)行GTID配置
#slave從庫(kù)上配置倆個(gè)主庫(kù)GTID復(fù)制 mysql> change master to -> master_host='192.168.136.219', #mysql02主庫(kù)ip -> master_user='app', #mysql02主庫(kù)授權(quán)的普通用戶 -> master_password='app', #mysql02主庫(kù)授權(quán)的普通用戶密碼 -> master_port=3306, #主庫(kù)端口 -> master_auto_position=1 for channel 'master01'; #位置從1開(kāi)始同步,并且第一個(gè)slave取名master01 mysql> change master to -> master_host='192.168.136.239', #mysql01主庫(kù)ip -> master_user='user', -> master_password='user', -> master_port=3306, #主庫(kù)端口 -> master_auto_position=1 for channel 'master02'; #位置從1開(kāi)始同步,并且第一個(gè)slave取名master01 #查看倆個(gè)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) #開(kāi)啟倆個(gè)slave mysql> start slave; #再次查看狀態(tài)
GTID(倆主一從)測(cè)試:
#master01主庫(kù)創(chuàng)建一個(gè)test數(shù)據(jù)庫(kù) 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主庫(kù)上查看 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | #沒(méi)有內(nèi)容 +--------------------+ 4 rows in set (0.00 sec) #slave從庫(kù)查看 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | #已經(jīng)同步了test庫(kù) +--------------------+ 5 rows in set (0.00 sec) #mysql02主庫(kù)創(chuàng)建一個(gè)RHCA數(shù)據(jù)庫(kù) 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從庫(kù) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | RHCA | | mysql | | performance_schema | | sys | #有了mysql01主庫(kù)的test庫(kù)和mysql02的RHCA的庫(kù) | test | +--------------------+ 6 rows in set (0.00 sec)
slave相關(guān)命令:
show slave status; //查看全部slave狀態(tài)
show slave status for channel ‘naem'; //查看單個(gè)slave狀態(tài)
reset slave; #重置全部slave
reset slave for channel ‘master1'; #重置單個(gè)slave
stop slave for channel ‘master1'; #暫停單個(gè)slave
start slave for channel ‘master1'; #開(kāi)啟單個(gè)slave
雖然我在做的過(guò)程沒(méi)有遇到錯(cuò)誤,但是下面這個(gè)是最最容易出現(xiàn)的錯(cuò)誤
配置完開(kāi)啟slave出現(xiàn)報(bào)錯(cuò)
mysql> start slave; ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
解決問(wèn)題
由于mysql.slave_relay_log_info表中保留了以前的復(fù)制信息,導(dǎo)致新從庫(kù)啟動(dòng)時(shí)無(wú)法找到對(duì)應(yīng)文件,那么我們清理掉該表中的記錄即可
mysql> reset slave; Query OK, 0 rows affected (0.00 sec)
以上就是MySQL示例DTID主從原理解析的詳細(xì)內(nèi)容,更多關(guān)于MySQL示例DTID主從原理的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
MySQL實(shí)現(xiàn)統(tǒng)計(jì)過(guò)去12個(gè)月每個(gè)月的數(shù)據(jù)信息
這篇文章主要介紹了MySQL實(shí)現(xiàn)統(tǒng)計(jì)過(guò)去12個(gè)月每個(gè)月的數(shù)據(jù)信息,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12mysql中整數(shù)數(shù)據(jù)類型tinyint詳解
大家好,本篇文章主要講的是mysql中整數(shù)數(shù)據(jù)類型tinyint詳解,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12mysql服務(wù)器無(wú)法啟動(dòng)的解決方法
本文主要介紹了mysql服務(wù)器無(wú)法啟動(dòng)的解決方法,mysql服務(wù)器無(wú)法啟動(dòng)時(shí),一般時(shí)配置文件和路徑的問(wèn)題,下面就來(lái)介紹一下解決方法,感興趣的可以了解一下2023-09-09MySQL中row_number的實(shí)現(xiàn)過(guò)程
這篇文章主要介紹了MySQL中row_number的實(shí)現(xiàn)過(guò)程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10Servermanager啟動(dòng)連接數(shù)據(jù)庫(kù)錯(cuò)誤如何解決
這篇文章主要介紹了Servermanager啟動(dòng)連接數(shù)據(jù)庫(kù)錯(cuò)誤如何解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10