MySQL全備+binlog恢復方法之偽裝master【原創】


利用mysql全備 +binlog server恢復方法之偽裝master

單實例試驗

一、試驗環境

10.72.7.40

實例 mysql3306為要恢復的對象,mysql3306的全備+binlog server(目錄/data/mysql/mysql3306/backup)

實例mysql3307為偽裝master

實例mysql3308為偽裝master的slave,在其上恢復數據

 

1、mysql3306全備

innobackupex --defaults-file=/data/mysql/mysql3306/mysql3306.cnf -S /tmp/mysql3306.sock -uroot -phch123 /root/backup

 

2、mysql3306的binlog server

root@localhost:mysql3306.sock [zst1]>show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000004 |       234 |
| mysql-bin.000005 |       234 |
+------------------+-----------+
2 rows in set (0.00 sec)

cd /data/mysql/mysql3306/backup

[root@bogon backup]# nohup mysqlbinlog --raw --read-from-remote-server --host=10.72.7.40 --port=3306 --user=root --password=hch123 --stop-never mysql-bin.000004 &

 

3、查看3306的數據

root@localhost:mysql3306.sock [zst1]>select count(*) from tb1;
+----------+
| count(*) |
+----------+
|       35 |
+----------+
1 row in set (0.00 sec)

模擬數據寫入

root@localhost:mysql3306.sock [zst1]>insert into tb1(c1, c2) select user,host from mysql.user;
Query OK, 9 rows affected (0.09 sec)
Records: 9  Duplicates: 0  Warnings: 0

root@localhost:mysql3306.sock [zst1]>insert into tb1(c1, c2) select user,host from mysql.user;
Query OK, 9 rows affected (0.14 sec)
Records: 9  Duplicates: 0  Warnings: 0

root@localhost:mysql3306.sock [zst1]>select count(*) from tb1;
+----------+
| count(*) |
+----------+
|       53 |
+----------+
1 row in set (0.00 sec)

root@localhost:mysql3306.sock [zst1]>select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| d20b918a-96c9-11e8-aae4-000c2969aede |
+--------------------------------------+
1 row in set (0.00 sec)

 

查看目前binlog位置

root@localhost:mysql3306.sock [zst1]>show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                       |
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------+
| mysql-bin.000005 |     1248 |              |                  | 959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-17 |
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

 

模擬誤操作

root@localhost:mysql3306.sock [zst1]>truncate table tb1;
Query OK, 0 rows affected (0.08 sec)

root@localhost:mysql3306.sock [zst1]>select * from tb1;
Empty set (0.00 sec)

root@localhost:mysql3306.sock [zst1]>select count(*) from tb1;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

 

繼續寫入數據

root@localhost:mysql3306.sock [zst1]>insert into tb1(c1, c2) select user,host from mysql.user;
Query OK, 9 rows affected (0.09 sec)
Records: 9  Duplicates: 0  Warnings: 0

root@localhost:mysql3306.sock [zst1]>select count(*) from tb1;
+----------+
| count(*) |
+----------+
|        9 |
+----------+
1 row in set (0.00 sec)

 

刷新binlog

root@localhost:mysql3306.sock [zst1]>flush logs;
Query OK, 0 rows affected (0.11 sec)

 

查看binlog信息

root@localhost:mysql3306.sock [zst1]>show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000004 |       234 |
| mysql-bin.000005 |      1952 |
| mysql-bin.000006 |       234 |
+------------------+-----------+
3 rows in set (0.00 sec)

root@localhost:mysql3306.sock [zst1]>show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                       |
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------+
| mysql-bin.000006 |      234 |              |                  | 959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-19 |
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

 

 

二、查看恢復位置

解析binlog

[root@bogon data]# mysqlbinlog -v --base64-output=decode-rows mysql-bin.000005 > 5.sql

 

 恢復的位置為 mysql-bin.000005 1248,d20b918a-96c9-11e8-aae4-000c2969aede:18

 

三、創建偽裝master 3308

1、初始化實例3308、啟動並修改密碼,省略……

2、查看3308 uuid信息

[root@bogon backup]# mysql -S /tmp/mysql3308.sock -uroot -phch123

查看uuid

root@localhost:mysql3308.sock [(none)]>select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| 8db05acd-a0f1-11e8-ad63-000c2969aede |
+--------------------------------------+
1 row in set (0.00 sec)

root@localhost:mysql3308.sock [(none)]>show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       177 |
| mysql-bin.000002 |       845 |
+------------------+-----------+
2 rows in set (0.00 sec)

 

 

3、將3306的binlog復制到3308上

先關閉3308實例

root@localhost:mysql3308.sock [(none)]>shutdown;
Query OK, 0 rows affected (0.00 sec)

root@localhost:mysql3308.sock [(none)]>exit

 

刪除3308的binlog

[root@bogon logs]# pwd
/data/mysql/mysql3308/logs
[root@bogon logs]# ll -thr
total 12K
-rw-r-----. 1 mysql mysql 177 Aug 15 21:13 mysql-bin.000001
-rw-r-----. 1 mysql mysql  88 Aug 15 21:16 mysql-bin.index
-rw-r-----. 1 mysql mysql 868 Aug 15 21:50 mysql-bin.000002
[root@bogon logs]# cat mysql-bin.index
/data/mysql/mysql3308/logs/mysql-bin.000001
/data/mysql/mysql3308/logs/mysql-bin.000002

 

拷貝3306binlog server的binlog至3308

[root@bogon logs]# cp /data/mysql/mysql3306/backup/* ./
[root@bogon logs]# ll -thr
total 16K
-rw-------. 1 root root  279 Aug 15 21:53 nohup.out
-rw-r-----. 1 root root  234 Aug 15 21:53 mysql-bin.000006
-rw-r-----. 1 root root 2.0K Aug 15 21:53 mysql-bin.000005
-rw-r-----. 1 root root  234 Aug 15 21:53 mysql-bin.000004

 

生成mysql-bin.index

[root@bogon logs]# ls /data/mysql/mysql3308/logs/mysql-bin.00000* > mysql-bin.index
[root@bogon logs]# cat  mysql-bin.index
/data/mysql/mysql3308/logs/mysql-bin.000004
/data/mysql/mysql3308/logs/mysql-bin.000005
/data/mysql/mysql3308/logs/mysql-bin.000006
[root@bogon logs]# ll -thr
total 20K
-rw-------. 1 root root  279 Aug 15 21:53 nohup.out
-rw-r-----. 1 root root  234 Aug 15 21:53 mysql-bin.000006
-rw-r-----. 1 root root 2.0K Aug 15 21:53 mysql-bin.000005
-rw-r-----. 1 root root  234 Aug 15 21:53 mysql-bin.000004
-rw-r--r--. 1 root root  258 Aug 15 21:55 mysql-bin.index
[root@bogon logs]# chown mysql. *
[root@bogon logs]# ll -thr
total 20K
-rw-------. 1 mysql mysql  279 Aug 15 21:53 nohup.out
-rw-r-----. 1 mysql mysql  234 Aug 15 21:53 mysql-bin.000006
-rw-r-----. 1 mysql mysql 2.0K Aug 15 21:53 mysql-bin.000005
-rw-r-----. 1 mysql mysql  234 Aug 15 21:53 mysql-bin.000004
-rw-r--r--. 1 mysql mysql  258 Aug 15 21:55 mysql-bin.index

[root@bogon logs]# rm -rf nohup.out 

 

 

啟動3308實例

[root@bogon backup]# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3308/mysql3308.cnf &

[root@bogon backup]# mysql -S /tmp/mysql3308.sock -uroot -phch123

root@localhost:mysql3308.sock [(none)]>select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| 8db05acd-a0f1-11e8-ad63-000c2969aede |
+--------------------------------------+
1 row in set (0.00 sec)

 

可以看到binlog已經識別出來了

root@localhost:mysql3308.sock [(none)]>show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000004 |       234 |
| mysql-bin.000005 |      1952 |
| mysql-bin.000006 |       234 |
| mysql-bin.000007 |       257 |
| mysql-bin.000008 |       234 |
+------------------+-----------+
5 rows in set (0.00 sec)

root@localhost:mysql3308.sock [(none)]>show master status;
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                                                                     |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000008 |      234 |              |                  | 8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,
959b9f31-75ef-11e8-97de-000c2969aede:61965-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-19 |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

 

可以看到Executed_Gtid_Set中多了8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,需要在slave 中gtid purged掉,否則會報1236錯誤(因為剛才新建賬號產生的log已經被刪除了)

 

四、創建偽裝master3308的slave3309

1、用3306的全備恢復

[root@bogon 2018-08-15_21-23-26]# pwd
/root/backup/2018-08-15_21-23-26
[root@bogon 2018-08-15_21-23-26]# innobackupex --apply-log /root/backup/2018-08-15_21-23-26

 

關閉3309

[root@bogon 2018-08-15_21-23-26]#mysql -S /tmp/mysql3309.sock -uroot -p
root@localhost:mysql3309.sock [(none)]>shutdown;

 

先備份3309的datadir,並清除里面的文件

[root@bogon data]# pwd
/data/mysql/mysql3309/data
[root@bogon mysql3309]# cp -a data/ data_bak
[root@bogon mysql3309]# cd data
[root@bogon data]# rm -rf *

 

將還原文件拷貝過來

[root@bogon data]# cp -r /root/backup/2018-08-15_21-23-26/* /data/mysql/mysql3309/data/

 

修改權限

[root@bogon data]# chown -R mysql. *

[root@bogon data]# ll -thr
total 421M
-rw-r-----. 1 mysql mysql  537 Aug 15 22:17 backup-my.cnf
drwxr-x---. 2 mysql mysql   86 Aug 15 22:17 hch
drwxr-x---. 2 mysql mysql   50 Aug 15 22:17 hch1
-rw-r-----. 1 mysql mysql  553 Aug 15 22:17 ib_buffer_pool
-rw-r-----. 1 mysql mysql 100M Aug 15 22:17 ibdata1
-rw-r-----. 1 mysql mysql 100M Aug 15 22:17 ib_logfile0
-rw-r-----. 1 mysql mysql 100M Aug 15 22:17 ib_logfile1
-rw-r-----. 1 mysql mysql 100M Aug 15 22:17 ib_logfile2
-rw-r-----. 1 mysql mysql  12M Aug 15 22:17 ibtmp1
drwxr-x---. 2 mysql mysql 4.0K Aug 15 22:17 mysql
drwxr-x---. 2 mysql mysql 8.0K Aug 15 22:17 performance_schema
drwxr-x---. 2 mysql mysql 8.0K Aug 15 22:17 sys
drwxr-x---. 2 mysql mysql   52 Aug 15 22:17 test
drwxr-x---. 2 mysql mysql   48 Aug 15 22:17 userdb
drwxr-x---. 2 mysql mysql 4.0K Aug 15 22:17 wubx
-rw-r--r--. 1 mysql mysql   22 Aug 15 22:17 xtrabackup_binlog_pos_innodb
-rw-r-----. 1 mysql mysql  109 Aug 15 22:17 xtrabackup_binlog_info
-rw-r-----. 1 mysql mysql  651 Aug 15 22:17 xtrabackup_info
-rw-r-----. 1 mysql mysql  117 Aug 15 22:17 xtrabackup_checkpoints
-rw-r-----. 1 mysql mysql 8.0M Aug 15 22:17 xtrabackup_logfile
-rw-r--r--. 1 mysql mysql    1 Aug 15 22:17 xtrabackup_master_key_id
drwxr-x---. 2 mysql mysql  192 Aug 15 22:17 zst
drwxr-x---. 2 mysql mysql   50 Aug 15 22:17 zst1

 

 

 查看備份的binlog位置為959b9f31-75ef-11e8-97de-000c2969aede:1-61970,d20b918a-96c9-11e8-aae4-000c2969aede:1-15

 

啟動3309實例

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3309/mysql3309.cnf &

[root@bogon data]# mysql -S /tmp/mysql3309.sock -uroot -phch123

root@localhost:mysql3309.sock [(none)]>show master status;
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                                                                 |
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000003 |      194 |              |                  | 61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2,
959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-15 |
+------------------+----------+--------------+------------------+-----------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) 

 

發現又多了個61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2,不太清楚是哪個gtid,查看3307的uuid也不是這個,為了影響實驗效果,下面的gtid_purged也把這個加入進去了

查看數據

root@localhost:mysql3309.sock [(none)]>select count(*) from zst1.tb1;
+----------+
| count(*) |
+----------+
|       35 |
+----------+
1 row in set (0.00 sec) 

 

設置gtid_purged,別忘記加入3308改密碼的gtid,並且加入了61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2

root@localhost:mysql3309.sock [(none)]>reset master;
Query OK, 0 rows affected (0.03 sec)

root@localhost:mysql3309.sock [(none)]>set global gtid_purged='959b9f31-75ef-11e8-97de-000c2969aede:1-61970,d20b918a-96c9-11e8-aae4-000c2969aede:1-15,8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2';
Query OK, 0 rows affected (0.00 sec)

root@localhost:mysql3309.sock [(none)]>change master to master_host='10.72.7.40', master_port=3308, master_user='hch', master_password='hch123', master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

root@localhost:mysql3309.sock [(none)]>start slave sql_thread until sql_before_gtids='d20b918a-96c9-11e8-aae4-000c2969aede:18';
Query OK, 0 rows affected (0.01 sec)

root@localhost:mysql3309.sock [(none)]>show slave status\G;                                                                                  
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.72.7.40
                  Master_User: hch
                  Master_Port: 3308
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: bogon-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              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: SQL_BEFORE_GTIDS
               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: 0
                  Master_UUID:
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      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: 61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2,
8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,
959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-15
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

root@localhost:mysql3309.sock [(none)]>select count(*) from zst1.tb1;                                                                        
+----------+
| count(*) |
+----------+
|       35 |
+----------+
1 row in set (0.01 sec)

root@localhost:mysql3309.sock [(none)]>start slave io_thread;
Query OK, 0 rows affected (0.00 sec)

root@localhost:mysql3309.sock [(none)]>select count(*) from zst1.tb1;
+----------+
| count(*) |
+----------+
|       53 |
+----------+
1 row in set (0.00 sec)

 

 

 

發現此時數據已經恢復了。

 

問題

報錯ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository

原因:設置gtid_purged,沒有加入了61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2

root@localhost:mysql3309.sock [(none)]>set global gtid_purged='959b9f31-75ef-11e8-97de-000c2969aede:1-61970,d20b918a-96c9-11e8-aae4-000c2969aede:1-15,8db05acd-a0f1-11e8-ad63-000c2969aede:1-3';
Query OK, 0 rows affected (0.02 sec)

root@localhost:mysql3309.sock [(none)]>change master to master_host='10.72.7.40', master_port=3308, master_user='hch', master_password='hch123', master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.09 sec)

root@localhost:mysql3309.sock [(none)]>start slave io_thread;
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
root@localhost:mysql3309.sock [(none)]>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.72.7.40
                  Master_User: hch
                  Master_Port: 3308
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: bogon-relay-bin.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: 1872
                   Last_Error: Slave failed to initialize relay log info structure from the repository
                 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: 1872
               Last_SQL_Error: Slave failed to initialize relay log info structure from the repository
  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: 180815 22:43:54
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: 8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,
959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-15
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

解決方法:

1、設置gtid_purged加入了61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2

2、reset slave all,重新設置主從

reset slave all

change master to master_host='10.72.7.40', master_port=3308, master_user='hch', master_password='hch123', master_auto_position=1;

start slave sql_thread until sql_before_gtids='d20b918a-96c9-11e8-aae4-000c2969aede:18';

具體操作過程如下:

root@localhost:mysql3309.sock [(none)]>reset master;
Query OK, 0 rows affected (0.03 sec)

root@localhost:mysql3309.sock [(none)]>set global gtid_purged='959b9f31-75ef-11e8-97de-000c2969aede:1-61970,d20b918a-96c9-11e8-aae4-000c2969aede:1-15,8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2';
Query OK, 0 rows affected (0.00 sec)

root@localhost:mysql3309.sock [(none)]>show slave status\G;                                                                                  
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.72.7.40
                  Master_User: hch
                  Master_Port: 3308
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: bogon-relay-bin.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: 1872
                   Last_Error: Slave failed to initialize relay log info structure from the repository
                 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: 1872
               Last_SQL_Error: Slave failed to initialize relay log info structure from the repository
  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: 180815 22:43:54
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: 61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2,
8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,
959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-15
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

root@localhost:mysql3309.sock [(none)]>stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

root@localhost:mysql3309.sock [(none)]>start slave sql_thread until sql_before_gtids='d20b918a-96c9-11e8-aae4-000c2969aede:18';
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
root@localhost:mysql3309.sock [(none)]>reset slave all;
Query OK, 0 rows affected (0.03 sec)

root@localhost:mysql3309.sock [(none)]>change master to master_host='10.72.7.40', master_port=3308, master_user='hch', master_password='hch123', master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)

root@localhost:mysql3309.sock [(none)]>start slave sql_thread until sql_before_gtids='d20b918a-96c9-11e8-aae4-000c2969aede:18';
Query OK, 0 rows affected (0.01 sec)

root@localhost:mysql3309.sock [(none)]>show slave status\G;                                                                                  
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.72.7.40
                  Master_User: hch
                  Master_Port: 3308
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: bogon-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              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: SQL_BEFORE_GTIDS
               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: 0
                  Master_UUID:
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      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: 61cfd125-a0f2-11e8-b8bc-000c2969aede:1-2,
8db05acd-a0f1-11e8-ad63-000c2969aede:1-3,
959b9f31-75ef-11e8-97de-000c2969aede:1-61970,
d20b918a-96c9-11e8-aae4-000c2969aede:1-15
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

root@localhost:mysql3309.sock [(none)]>select count(*) from zst1.tb1;                                                                        
+----------+
| count(*) |
+----------+
|       35 |
+----------+
1 row in set (0.01 sec)

root@localhost:mysql3309.sock [(none)]>start slave io_thread;
Query OK, 0 rows affected (0.00 sec)

root@localhost:mysql3309.sock [(none)]>select count(*) from zst1.tb1;
+----------+
| count(*) |
+----------+
|       53 |
+----------+
1 row in set (0.00 sec)

參考

利用binlogserver恢復單表實驗【轉】 - paul_hch - 博客園 https://www.cnblogs.com/paul8339/p/9378269.html

通過全備+binlog_server同步恢復被drop的庫或表 - 2森林 - 博客園 https://www.cnblogs.com/2woods/p/9394625.html

ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository - 西橙 - 博客園 https://www.cnblogs.com/Bccd/p/5856716.html

利用偽master主機來增量恢復mysql - CSDN博客 https://blog.csdn.net/zengxuewen2045/article/details/51465078

 

  多台機器試驗

 

主機10.72.16.50的MySQL 3306實例

偽裝master 10.72.16.50的3307實例

偽裝master的slave 10.72.16.112 3306實例

 

一、創建試驗環境

10.72.16.50的MySQL 3306實例執行

1、備份數據庫

innobackupex --defaults-file=/etc/my.cnf -uroot -phch123 /root/test

2、模擬誤刪除

mysql> use hch;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from tb1;
+----+-------+
| id | cname |
+----+-------+
|  1 | php   |
|  2 | java  |
|  3 | go    |
+----+-------+
3 rows in set (0.03 sec)

mysql> insert into tb1(cname) values('test');
Query OK, 1 row affected (0.06 sec)

mysql> insert into tb1(cname) values('test1');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tb1(cname) values('test2');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tb1(cname) values('test3');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tb1(cname) values('test4');
Query OK, 1 row affected (0.00 sec)

mysql> select * from tb1;
+----+-------+
| id | cname |
+----+-------+
|  1 | php   |
|  2 | java  |
|  3 | go    |
|  4 | test  |
|  5 | test1 |
|  6 | test2 |
|  7 | test3 |
|  8 | test4 |
+----+-------+
8 rows in set (0.00 sec)

mysql> insert into tb1(cname) values('test5');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tb1(cname) values('test6');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tb1(cname) values('test7');
Query OK, 1 row affected (0.00 sec)

mysql> insert into tb1(cname) values('test8');
Query OK, 1 row affected (0.01 sec)

mysql> select * from tb1;
+----+-------+
| id | cname |
+----+-------+
|  1 | php   |
|  2 | java  |
|  3 | go    |
|  4 | test  |
|  5 | test1 |
|  6 | test2 |
|  7 | test3 |
|  8 | test4 |
|  9 | test5 |
| 10 | test6 |
| 11 | test7 |
| 12 | test8 |
+----+-------+
12 rows in set (0.00 sec)

執行誤操作
mysql> truncate table tb1;
Query OK, 0 rows affected (0.15 sec)

查看binlog位置
mysql> show master status\G;
*************************** 1. row ***************************
             File: mysql-bin.000002
         Position: 2731
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set: 22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
671bac73-a032-11e8-a493-000c29bf3444:1-11,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753
1 row in set (0.00 sec)

ERROR:
No query specified

刷新日志
mysql> flush logs;
Query OK, 0 rows affected (0.08 sec)

mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| 671bac73-a032-11e8-a493-000c29bf3444 |
+--------------------------------------+
1 row in set (0.02 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                                                                                                            |
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000003 |      234 |              |                  | 22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
671bac73-a032-11e8-a493-000c29bf3444:1-11,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753 |
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

 

3、查看誤操作binlog日志位置

mysqlbinlog -v --base64-output=decode-rows mysql-bin.000002 > 2.sql

位置為mysql-bin.000002的2582,gtid為671bac73-a032-11e8-a493-000c29bf3444:11

 

二、在10.72.16.50上創建3307的偽裝master

1、初始化3307

[root@hchtest3 data]# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf --initialize

[root@hchtest3 data]# cat error.log
2018-08-15T09:21:50.046760Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-15T09:21:53.749883Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-15T09:21:54.164271Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-15T09:21:54.572772Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a68949d2-a06c-11e8-bba3-000c29bf3444.
2018-08-15T09:21:54.581852Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-15T09:21:54.586219Z 1 [Note] A temporary password is generated for root@localhost: 8/IHqjytdouM

 

2、啟動3307

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf &

 

登錄修改密碼並關閉

[root@hchtest3 data]# mysql -S /tmp/mysql3307.sock -uroot -p

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.03 sec)

mysql> alter user user() identified by 'hch123';

創建復制賬號
mysql> grant all privileges on *.* to hch@'%' identified by 'hch123'; mysql
> flush privileges; mysql> shutdown; Query OK, 0 rows affected (0.02 sec)

 

3、拷貝50的3306 binlog至3307 datadir下

rm -rf /data/mysql/mysql3307/data/mysql-bin.*

cp -a /data/mysql/mysql3306/backup/* /data/mysql/mysql3306/data/

創建mysql-bin.index

[root@hchtest3 data]# ls /data/mysql/mysql3307/data/mysql-bin.* > mysql-bin.index

[root@hchtest3 data]# cat mysql-bin.index
/data/mysql/mysql3307/data/mysql-bin.000001
/data/mysql/mysql3307/data/mysql-bin.000002
/data/mysql/mysql3307/data/mysql-bin.000003

修改權限
chown mysql. mysql-bin.*

4、啟動偽裝master 3307實例

/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf &

5、查看binlog日志

mysql> show master logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       493 |
| mysql-bin.000002 |      2778 |
| mysql-bin.000003 |       234 |
| mysql-bin.000004 |       234 |
+------------------+-----------+

mysql> show master status;
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                                                         |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000004 |      234 |              |                  | 671bac73-a032-11e8-a493-000c29bf3444:1-11,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
a68949d2-a06c-11e8-bba3-000c29bf3444:1 |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| a68949d2-a06c-11e8-bba3-000c29bf3444 |
+--------------------------------------+
1 row in set (0.00 sec)

查看binlog位置發現多了a68949d2-a06c-11e8-bba3-000c29bf3444:1,這個為3307初始化后添加密碼操作產生的gtid,設置偽裝master從庫時gtid_purged需要添加這個否則會1236報錯

 

三、設置偽裝master 10.72.16.50 3307的slave 10.72.16.112 3306

1、用10.72.16.50 3306的全備還原

innobackupex --apply-log /root/test/2018-08-15_15-54-24

2、查看binlog日志備份位置

[root@hchtest3 2018-08-15_15-54-24]# cat xtrabackup_binlog_info 
mysql-bin.000002    234    22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
671bac73-a032-11e8-a493-000c29bf3444:1,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753
[root@hchtest3 2018-08-15_15-54-24]# cat xtrabackup_info 
uuid = 7b379338-a060-11e8-8a15-000c29bf3444
name = 
tool_name = innobackupex
tool_command = --defaults-file=/data/mysql/mysql3306/my3306.cnf -uroot -phch123 /root/test
tool_version = 2.4.12
ibbackup_version = 2.4.12
server_version = 5.7.17-log
start_time = 2018-08-15 15:54:29
end_time = 2018-08-15 15:54:47
lock_time = 0
binlog_pos = filename 'mysql-bin.000002', position '234', GTID of the last change '22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
671bac73-a032-11e8-a493-000c29bf3444:1,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753'

位置為

 
        
mysql-bin.000002    234    22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
671bac73-a032-11e8-a493-000c29bf3444:1,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753
 

拷貝10.72.16.112的3306 datadir下,之前要停止10.72.16.112的3306,並清除datadir目錄。

[root@hchtest3 2018-08-15_15-54-24]# scp -r * root@10.72.16.112:/usr/local/mysql/data/

 

3、啟動slave並設置同步

[root@hchtest4 script]# service mysql status
MySQL running (16977)                                      [  OK  ]


mysql> reset master;
Query OK, 0 rows affected (0.00 sec)

此處要加入50的3307的gtid mysql
> SET @@GLOBAL.GTID_PURGED='22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,671bac73-a032-11e8-a493-000c29bf3444:1,909c25b1-7f67-11e8-9b9d-000c29bf3444:1,ee639e4e-358a-11e7-87fa-000c29466957:1-753,a68949d2-a06c-11e8-bba3-000c29bf3444:1'; mysql> change master to master_host='10.72.16.50', master_port=3307, master_user='hch', master_password='hch123', master_auto_position=1; Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql> start slave sql_thread until sql_before_gtids='671bac73-a032-11e8-a493-000c29bf3444:11'; Query OK, 0 rows affected (0.03 sec) mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Master_Host: 10.72.16.50 Master_User: hch Master_Port: 3307 Connect_Retry: 60 Master_Log_File: Read_Master_Log_Pos: 4 Relay_Log_File: mysql-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: Slave_IO_Running: No Slave_SQL_Running: Yes 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: SQL_BEFORE_GTIDS 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: 0 Master_UUID: Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL 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: 22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109, 671bac73-a032-11e8-a493-000c29bf3444:1, 909c25b1-7f67-11e8-9b9d-000c29bf3444:1, a68949d2-a06c-11e8-bba3-000c29bf3444:1, ee639e4e-358a-11e7-87fa-000c29466957:1-753 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) ERROR: No query specified mysql> start slave io_thread; Query OK, 0 rows affected (0.00 sec) mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.72.16.50 Master_User: hch Master_Port: 3307 Connect_Retry: 60 Master_Log_File: mysql-bin.000004 Read_Master_Log_Pos: 665 Relay_Log_File: mysql-relay-bin.000002 Relay_Log_Pos: 2715 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes 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: 2582 Relay_Log_Space: 4716 Until_Condition: SQL_BEFORE_GTIDS 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: 503307 Master_UUID: a68949d2-a06c-11e8-bba3-000c29bf3444 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: 671bac73-a032-11e8-a493-000c29bf3444:2-11, a68949d2-a06c-11e8-bba3-000c29bf3444:2-3 Executed_Gtid_Set: 22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109, 671bac73-a032-11e8-a493-000c29bf3444:1-10, 909c25b1-7f67-11e8-9b9d-000c29bf3444:1, a68949d2-a06c-11e8-bba3-000c29bf3444:1, ee639e4e-358a-11e7-87fa-000c29466957:1-753 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) ERROR: No query specified
查看發現數據已經恢復 mysql
> select * from hch.tb1; +----+-------+ | id | cname | +----+-------+ | 1 | php | | 2 | java | | 3 | go | | 4 | test | | 5 | test1 | | 6 | test2 | | 7 | test3 | | 8 | test4 | | 9 | test5 | | 10 | test6 | | 11 | test7 | | 12 | test8 | +----+-------+ 12 rows in set (0.02 sec)

 

問題

slave設置時報錯1236

mysql> start slave io_thread;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 10.72.16.50
                  Master_User: hch
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: 
          Read_Master_Log_Pos: 4
               Relay_Log_File: mysql-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: 
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              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: SQL_BEFORE_GTIDS
               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: 1236
                Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 503307
                  Master_UUID: a68949d2-a06c-11e8-bba3-000c29bf3444
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 180815 18:02:12
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,
671bac73-a032-11e8-a493-000c29bf3444:1,
909c25b1-7f67-11e8-9b9d-000c29bf3444:1,
ee639e4e-358a-11e7-87fa-000c29466957:1-753
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

 

原因為set gtid_purged時未加入偽裝master 10.72.16.50 3307 的gtid信息a68949d2-a06c-11e8-bba3-000c29bf3444:1

解決方法如下:

mysql> reset slave all;
Query OK, 0 rows affected (0.05 sec)

mysql> SET @@GLOBAL.GTID_PURGED='22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,671bac73-a032-11e8-a493-000c29bf3444:1,909c25b1-7f67-11e8-9b9d-000c29bf3444:1,ee639e4e-358a-11e7-87fa-000c29466957:1-753,a68949d2-a06c-11e8-bba3-000c29bf3444:1';
ERROR 1840 (HY000): @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.
mysql> reset master;
Query OK, 0 rows affected (0.00 sec)

mysql> SET @@GLOBAL.GTID_PURGED='22dc7409-2cd5-11e7-888c-000c29bf3444:1-984109,671bac73-a032-11e8-a493-000c29bf3444:1,909c25b1-7f67-11e8-9b9d-000c29bf3444:1,ee639e4e-358a-11e7-87fa-000c29466957:1-753,a68949d2-a06c-11e8-bba3-000c29bf3444:1';
Query OK, 0 rows affected (0.00 sec) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM