MySQL主從同步故障-Slave_SQL_Running: No

來源:互聯網
上載者:User

標籤:

故障現象:

進入slave伺服器,運行:

mysql> show slave status\G

         .......
             Relay_Log_File: localhost-relay-bin.000535
              Relay_Log_Pos: 21795072
      Relay_Master_Log_File: localhost-bin.000094
          Slave_IO_Running: Yes
          Slave_SQL_Running: No
            Replicate_Do_DB: 
        Replicate_Ignore_DB: 
       ......

解決辦法一、

Slave_SQL_Running: No
1.程式可能在slave上進行了寫操作

2.也可能是slave機器重起後,交易回復造成的.

一般是交易回復造成的:
解決辦法:
mysql> slave stop;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;

解決辦法二、

首先停掉Slave服務:slave stop
到主伺服器上查看主機狀態:
記錄File和Position對應的值

進入master

mysql> show master status;
+----------------------+----------+--------------+------------------+
| File                 | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------------+----------+--------------+------------------+
| localhost-bin.000094 | 33622483 |              |                  | 
+----------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

然後到slave伺服器上執行手動同步:

mysql> change master to 
> master_host=‘master_ip‘,
> master_user=‘user‘, 
> master_password=‘pwd‘, 
> master_port=3306, 
> master_log_file=localhost-bin.000094‘, 
> master_log_pos=33622483 ;
1 row in set (0.00 sec)
mysql> slave start;
1 row in set (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
........
            Master_Log_File: localhost-bin.000094
        Read_Master_Log_Pos: 33768775
             Relay_Log_File: localhost-relay-bin.000537
              Relay_Log_Pos: 1094034
      Relay_Master_Log_File: localhost-bin.000094
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            Replicate_Do_DB:

手動同步需要停止master的寫操作!

查看mysql主從配置的狀態及修正 slave不啟動問題

1、查看master的狀態
show master status;  //Position不應該為0
show processlist;  
//state狀態應該為Has sent all binlog to slave; waiting for binlog to be updated
2、查看slave狀態
show slave status;
//Slave_IO_Running 與 Slave_SQL_Running 狀態都要為Yes
show processlist;
//應該有兩行state值為:
Has read all relay log; waiting for the slave I/O thread to update it
Waiting for master to send event

3、錯誤記錄檔
MySQL安裝目錄 /usr/local/mysql
MySQL日誌目錄 /usr/local/mysql/data/   形如,Hostname.err

4、Change master to
如果從庫的Slave未啟動,Slave_IO_Running為NO。
可能是主庫是的master的資訊有變化,
查看主庫show master status;
記錄下File,Position欄位,假設為‘mysql-bin.000004’,98;
在從庫執行:

 mysql>stop slave;
 mysql>change master to master_log_file=‘mysql-bin.000004‘,master_log_pos=98;
 mysql>start slave;


5、SET global sql_slave_skip_counter=n;
如果從庫的slave_sql_running為NO。
Err檔案中記錄:
Slave:Error "Duplicate entry ‘1‘ for key 1" on query.....
可能是master未向slave同步成功,但slave中已經有了記錄。造成的衝突可以在從庫上執行
set global sql_slave_skip_counter=n;
跳過幾步。再restart slave就可以了。

 6、同步錯誤處理
發現mysql slave伺服器經常因為一些特殊字元或者符號產生的更新語句報錯,整個同步也會因此而卡在那,最初的辦法只是手動去出錯的機器執行下面三條SQL語句,跳過錯誤即可。

 mysql>slave stop;
 mysql>set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 mysql>slave start;


PS:本人多次遇到從資料庫的同步進程自動停掉的問題,有時簡單通過slave stop,slave start即可解決。有時slave start啟動後又會自動停掉,這時使用 change master重設主要資料庫資訊的方式解決了問題。


說明:

Slave_IO_Running:串連到主庫,並讀取主庫的日誌到本地,產生本地記錄檔

Slave_SQL_Running:讀取本地記錄檔,並執行日誌裡的SQL命令。


MySQL主從同步故障-Slave_SQL_Running: No

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.