中關(guān)村在線官方網(wǎng)站電腦首頁關(guān)鍵詞排名
目錄
查看主從是否同步
詳解Slave_IO、Slave_SQL?
判斷主從完全同步
各個(gè) Log_File 和 Log_Pos的關(guān)系
修復(fù)命令
查看主從是否同步
show slave status;
Slave_IO_Running、Slave_SQL_Running,這兩個(gè)值是Yes表示正常,No是異常
使用豎排顯示:
Name |Value |
-----------------------------+------------------------------------------------------+
Slave_IO_State |Waiting for master to send event |
Master_Host |192.168.20.161 |
Master_User |root |
Master_Port |3306 |
Connect_Retry |60 |
Master_Log_File |mysql-bin.004651 |
Read_Master_Log_Pos |300004719 |
Relay_Log_File |xxxx-relay-bin.002999 |
Relay_Log_Pos |300004932 |
Relay_Master_Log_File |mysql-bin.004651 |
Slave_IO_Running |Yes |
Slave_SQL_Running |Yes |
Replicate_Do_DB |alisaas |
Replicate_Ignore_DB |mysql,information_schema,performation_schema,sys |
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 |300004719 |
Relay_Log_Space |300005190 |
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 |0 |
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 |161 |
Master_UUID |000fe6d4-25cd-21eb-a102-1111efa99c99 |
Master_Info_File |/sata01/data/mysql/master.info |
SQL_Delay |0 |
SQL_Remaining_Delay | |
Slave_SQL_Running_State |Slave has read all relay log; waiting for more updates|
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 | |
Auto_Position |0 |
Replicate_Rewrite_DB | |
Channel_Name | |
Master_TLS_Version | |
詳解Slave_IO、Slave_SQL?
Slave_IO線程負(fù)責(zé)把主庫的bin日志(Master_Log)內(nèi)容,抄寫到從庫的中繼日志上(Relay_Log)。
Slave_SQL線程負(fù)責(zé)把中繼日志上的語句在從庫上執(zhí)行一遍。
?
Slave_IO線程相對(duì)比較簡(jiǎn)單,一般不容易出錯(cuò)。如果Slave_IO_Running顯示為No,多為網(wǎng)絡(luò)連接不上,權(quán)限不夠等環(huán)境問題。
Slave_SQL線程相對(duì)容易出錯(cuò),例如人為手動(dòng)的在從庫插入一條數(shù)據(jù),造成主從不一致。但此時(shí)兩個(gè)線程的狀態(tài)仍然是正常的。等到主庫也插入一條同樣的數(shù)據(jù)時(shí),通知從庫做相同操作,從庫會(huì)出現(xiàn)主鍵重復(fù)的錯(cuò)誤。此時(shí)Slave_SQL_Running的狀態(tài)會(huì)變?yōu)镹o,而Last_SQL_Error,Last_SQL_Error_Timestamp會(huì)記錄錯(cuò)誤的原因和發(fā)生時(shí)間。
Slave_SQL線程會(huì)停止后續(xù)的SQL語句執(zhí)行,因?yàn)樗庾R(shí)到往后執(zhí)行會(huì)導(dǎo)致錯(cuò)誤修復(fù)的難度增加。但Slave_IO線程不會(huì)停止,會(huì)繼續(xù)抄log的工作。所以中繼log依然是最新的。
這時(shí)候Master_Log_File: mysql-bin.000002?和 ?Relay_Master_Log_File: mysql-bin.000001之間就產(chǎn)生了偏差。
以上面為例,主庫的日志已經(jīng)寫到了 mysql-bin.000001,而從庫依然停留在 mysql-bin.000002等待人工修復(fù)錯(cuò)誤。
那么當(dāng)錯(cuò)誤修復(fù)后,只需用stop slave和start slave重啟下同步。Slave_SQL線程會(huì)重新的嘗試工作。
如果沒有問題,那么Slave_SQL的狀態(tài)會(huì)變回Yes。但此時(shí)主從并沒有完全同步,需要一點(diǎn)時(shí)間。
判斷主從完全同步
若完全同步,可通過以下幾條判斷:
1. 首先 Master_Log_File 和 Relay_Master_Log_File 所指向的文件必須一致。
例如本案例中是mysql-bin.004651
2.?Read_Master_Log_Pos = Exec_Master_Log_Pos 時(shí),則表明 slave 和 master 處于完全同步的狀態(tài)。例如本案例中是:300004719
Read_Master_Log_Pos 是io讀到的位置,Exec_Master_Log_Pos 是sql執(zhí)行到的位置。
1和2合并即:
Relay_Master_Log_File = Master_Log_File
Read_Master_Log_Pos = Exec_Master_Log_Pos
3. 此時(shí),有幾個(gè)字段值如下:
Slave_IO_State: Waiting for master to send event。意思是等待主庫送事件過來
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it。意思是從庫已經(jīng)讀完所有的relay log,等待從庫的IO線程繼續(xù)更新。
各個(gè) Log_File 和 Log_Pos的關(guān)系
1) The position, ON THE MASTER, from which the I/O thread is reading:
Master_Log_File/Read_Master_Log_Pos. -----相對(duì)于主庫,從庫讀取主庫的二進(jìn)制日志的位置,是IO線程
2) The position, IN THE RELAY LOGS, at which the SQL thread is executing:
Relay_Log_File/Relay_Log_Pos?----相對(duì)于從庫,是從庫的sql線程執(zhí)行到的位置
3) The position, ON THE MASTER, at which the SQL thread is executing:
Relay_Master_Log_File/Exec_Master_Log_Pos?----相對(duì)于主庫,是從庫的sql線程執(zhí)行到的位置
show slave status\G中的Read_Master_Log_Pos和Relay_Log_Pos的(大小)關(guān)系_lovely可愛歐辰的博客-CSDN博客
修復(fù)命令
執(zhí)行以下3條命令??梢栽趎avicat、dbeaver、或者cmd窗口,都行。
stop slave;
set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
start slave;
一次不行,多執(zhí)行幾次?;蛘咝薷臄?shù)值1,改成2,或者3。前提是你知道怎么玩,不會(huì)玩的話,就用1,多執(zhí)行幾次。
Mysql主從錯(cuò)誤之Slave_SQL_Running No - 簡(jiǎn)書
關(guān)于set global sql_slave_skip_counter=N 命令的解釋_Mr. Sun_的博客-CSDN博客
Mysql主從同步時(shí)Slave_IO_Running:Connecting ; Slave_SQL_Running:Yes的情況故障排除_MegaBytes的博客-CSDN博客
Mysql主從同步時(shí)Slave_IO_Running:Connecting ; Slave_SQL_Running:Yes的情況故障排除_爽姐想退休的博客-CSDN博客
show slave status判斷主從同步狀態(tài)_chagaostu的博客-CSDN博客
mysql查看主從同步狀態(tài)的方法_mysql_Full Stack Developme-華為云開發(fā)者聯(lián)盟
MySQL :: MySQL 5.7 Reference Manual :: 16.1.2 Setting Up Binary Log File Position Based Replication
=========================分割線============================?
文章到此已經(jīng)結(jié)束,以下是紫薯布丁
show slave status;
stop slave;
set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
start slave;
Name ? ? ? ? ? ? ? ? ? ? ? ? |Value ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
-----------------------------+------------------------------------------------------+
Slave_IO_State ? ? ? ? ? ? ? |Waiting for master to send event ? ? ? ? ? ? ? ? ? ? ?|
Master_Host ? ? ? ? ? ? ? ? ?|192.168.20.161 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Master_User ? ? ? ? ? ? ? ? ?|root ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Master_Port ? ? ? ? ? ? ? ? ?|3306 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Connect_Retry ? ? ? ? ? ? ? ?|60 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Master_Log_File ? ? ? ? ? ? ?|mysql-bin.004651 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Read_Master_Log_Pos ? ? ? ? ?|300004719 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Relay_Log_File ? ? ? ? ? ? ? |xxxx-relay-bin.002999 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Relay_Log_Pos ? ? ? ? ? ? ? ?|300004932 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Relay_Master_Log_File ? ? ? ?|mysql-bin.004651 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Slave_IO_Running ? ? ? ? ? ? |Yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Slave_SQL_Running ? ? ? ? ? ?|Yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Replicate_Do_DB ? ? ? ? ? ? ?|alisaas ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Replicate_Ignore_DB ? ? ? ? ?|mysql,information_schema,performation_schema,sys ? ? ?|
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 ? ? ? ? ?|300004719 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Relay_Log_Space ? ? ? ? ? ? ?|300005190 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
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 ? ? ? ?|0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
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 ? ? ? ? ? ? |161 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Master_UUID ? ? ? ? ? ? ? ? ?|000fe6d4-25cd-21eb-a102-1111efa99c99 ? ? ? ? ? ? ? ? ?|
Master_Info_File ? ? ? ? ? ? |/sata01/data/mysql/master.info ? ? ? ? ? ? ? ? ? ? ? ?|
SQL_Delay ? ? ? ? ? ? ? ? ? ?|0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
SQL_Remaining_Delay ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Slave_SQL_Running_State ? ? ?|Slave has read all relay log; waiting for more updates|
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 ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Auto_Position ? ? ? ? ? ? ? ?|0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
Replicate_Rewrite_DB ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Channel_Name ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
Master_TLS_Version ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|