利用當天的xtrabackup全量備份文件搭建slave庫

環境:

單臺機器開啓2個mysql實例 3306和3307,
3306 和3307實例都開啓了Gtid,並且要保證server-id不同

全量備份命令:

time innobackupex --defaults-file=/data/mysql5.7/my3306.cnf  -ubackupuser -p123456ccs  --host=127.0.0.1  -S /tmp/3306.sock /data/backup/

當天的xtrabackup全量備份文件記錄的binlog的位置點:

[root@e ~]# cat /data/backup/2019-08-16_17-59-10/xtrabackup_binlog_info 
mysql-bin.000009    117268  efdcb9c7-bf3d-11e9-b0bf-90b11c20454d:1-876

恢復備份到新的實例mysql3307的上:

innobackupex  --apply-log /data/backup/2019-08-16_17-59-10/
innobackupex --defaults-file=/data/mysql5.7/my3307.cnf --copy-back /data/backup/2019-08-16_17-59-10/

授權新實例data目錄mysql的權限:

chown -R mysql.mysql /data/mysql5.7/3307/data 

提示:/data/mysql5.7/my3307.cnf 配置文件要開啓gtid,並且要註釋掉定時器:#event_scheduler = ON,默認定時器是關閉的

啓動mysql 3307 實例:

/usr/local/mysql5.7/bin/mysqld --defaults-file=/data/mysql5.7/my3307.cnf &

mysql> show variables like 'event_scheduler'
    -> ;
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | OFF   |
+-----------------+-------+
1 row in set (0.01 sec)

[root@e data]# mysql -uroot -p'lnmp.org#25199' -S /tmp/3307.sock -e "select @@port"
Warning: Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|   3307 |
+--------+

在3306庫上創建複製賬戶:

grant replication slave *.* to 'rep'@'192.168.0.%' identified by '654321testrep';flush privileges;

清除3307實例的Gtid信息:

mysql> reset master;

當天的xtrabackup全量備份文件記錄的binlog的位置點以及事物gtid執行結束的位置:

[root@e ~]# cat /data/backup/2019-08-16_17-59-10/xtrabackup_binlog_info 
mysql-bin.000009    117268  efdcb9c7-bf3d-11e9-b0bf-90b11c20454d:1-876

3307 slave實例上要讓gtid號從efdcb9c7-bf3d-11e9-b0bf-90b11c20454d:1-876 以後開始記錄:

  mysql> set global gtid_purged='efdcb9c7-bf3d-11e9-b0bf-90b11c20454d:1-876';
  mysql> show master status\G
*************************** 1. row ***************************
             File: mysql-bin.000001
         Position: 154
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: efdcb9c7-bf3d-11e9-b0bf-90b11c20454d:1-876
1 row in set (0.00 sec)

3307 slave實例上執行:

  CHANGE MASTER TO
  MASTER_HOST='192.168.0.1',
  MASTER_USER='rep',
  MASTER_PASSWORD='654321testrep',
  MASTER_PORT=3306,
  MASTER_AUTO_POSITION = 1;

start slave;show slave status\G

slave庫上查看:

[root@e data]# mysql -uroot -p'lnmp.org#25199' -S /tmp/3307.sock -e "show slave status\G"|egrep "Slave_IO|Slave_SQL"
Warning: Using a password on the command line interface can be insecure.
               Slave_IO_State: Waiting for master to send event
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more update

到此處主從複製搭建完成

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章