【MySQL】数据库复制:MySQL 5.7 GTID Replication

[root@wallet01 ~]# wget https://repo.percona.com/yum/percona-release-latest.noarch.rpm
[root@wallet01 ~]# rpm -ivh percona-release-latest.noarch.rpm
[root@wallet01 ~]# yum install -y percona-xtrabackup-24

[root@wallet01 ~]# vim /etc/my.cnf
[mysqld]
server_id = 201
log_bin = mysql-bin
binlog_format = row
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 4G
max_binlog_size = 128M
expire_logs_days = 7
binlog_rows_query_log_events = on
gtid_mode = on
enforce_gtid_consistency = on

[root@wallet01 ~]# mysql -uroot -p
Enter password: 
mysql> create user xtrabackup@'localhost' identified by 'xtrabackup';
Query OK, 0 rows affected (0.10 sec)

mysql> grant reload,lock tables,replication client,process on *.* to xtrabackup@'localhost';
Query OK, 0 rows affected (0.02 sec)

mysql> grant replication slave on *.* to 'repl'@'192.168.1.%' identified by 'repl';
Query OK, 0 rows affected (0.11 sec)

mysql> flush privileges; 
Query OK, 0 rows affected (0.05 sec)

[mysql@wallet01 ~]$ ssh-keygen
[mysql@wallet01 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub mysql@wallet02
[mysql@wallet01 ~]$ ssh wallet02 date
Mon Feb 18 10:41:16 CST 2019

[mysql@wallet01 ~]$ xtrabackup --backup --user=xtrabackup --password=xtrabackup \
--stream=tar | ssh mysql@wallet02 \ "gzip >/home/mysql/backup/`date '+%Y-%m-%d_%H-%M-%S'`.tar.gz"


[root@wallet02 ~]# wget https://repo.percona.com/yum/percona-release-latest.noarch.rpm
[root@wallet02 ~]# rpm -ivh percona-release-latest.noarch.rpm
[root@wallet02 ~]# yum install -y percona-xtrabackup-24

[root@wallet02 ~]# vim /etc/my.cnf
[mysqld]
server_id = 202
master_info_repository = table
relay_log_info_repository = table
relay_log = relay-bin
relay_log_recovery = 1
gtid_mode = on
enforce_gtid_consistency = on
super_read_only = 1

[root@wallet02 ~]# cd /home/mysql/backup
[root@wallet02 backup]$ tar izxvf 2019-02-18_10-42-09.tar.gz 

[root@wallet02 backup]$ cat xtrabackup_binlog_info
mysql-bin.000017        18251541        17aa497f-cd7b-11eb-9521-000c29f06629:1-252

[root@wallet02 ~]# xtrabackup --prepare --target-dir=/home/mysql/backup
[root@wallet02 ~]# xtrabackup --copy-back --target-dir=/home/mysql/backup
[root@wallet02 ~]# chown -R mysql:mysql /var/lib/mysql

[root@wallet02 ~]# service mysqld start
Logging to '/var/lib/mysql/wallet02.err'.
Starting mysqld:                                           [  OK  ]

[root@wallet02 ~]# mysql -uroot -p
Enter password: 
mysql> set global gtid_purged='17aa497f-cd7b-11eb-9521-000c29f06629:1-252';
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.11 sec)

mysql> set global gtid_purged='17aa497f-cd7b-11eb-9521-000c29f06629:1-252';
Query OK, 0 rows affected (0.03 sec)

mysql> change master to \
    master_host='192.168.1.201', \
    master_user='repl', \
    master_password='repl', \
    master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.29 sec)

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

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.201
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000017
          Read_Master_Log_Pos: 38525587
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 20274460
        Relay_Master_Log_File: mysql-bin.000017
             Slave_IO_Running: Yes
            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: 38525587
              Relay_Log_Space: 20274661
              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: 201
                  Master_UUID: 17aa497f-cd7b-11eb-9521-000c29f06629
             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: 17aa497f-cd7b-11eb-9521-000c29f06629:253-3418
            Executed_Gtid_Set: 17aa497f-cd7b-11eb-9521-000c29f06629:1-3418
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
上一篇:Java零基础入门视频,大爆料!Github上100


下一篇:实现原理讲解!java字符串比较大小规则