gtid主从同步

版权声明:如需转载请私信我,经我同意才可转载,转载需附上原地址。 https://blog.csdn.net/qq_26553835/article/details/84063031

环境说明

主机名 ip 服务
zhu 192.168.100.233 mysql
cong 192.168.100.234 mysql

二进制安装mysql
主:配置文件

[root@server data]# vim /etc/my.cnf

[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/111.pid
user = mysql
skip-name-resolve
#GTID
server-id=135          \\服务器id
gtid-mode = ON        \\开启gtid模式
enforce-gtid-consistency = ON      \\强制gtid一致性,开启后对于特定create table不被支持
#BINLOG
log-slave-updates = 1
log-bin=master-binlog
binlog-format=row              
#relay log
skip-slave-start=1

vim /etc/my.cnf

[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
#gtid
gtid-mode=on
enforce-gtid-consistency=on
server-id=143
#binlog
log-bin=slave-binlog
log-slave-updates=1
binlog_format=row
#relay log
skip_slave_start=1
skip-grant-tables

创建用户授权 zhu

mysql> create user haha@'192.168.118.112' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave on *.* to 'haha'@'192.168.118.112';
Query OK, 0 rows affected (0.00 sec)

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

配置gtid的复制cong

mysql> change master to
    master_host='192.168.118.222',
    master_user='haha',
    master_password='123456',
    master_port=3306,
    master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

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

zhu

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.100.233
                  Master_User: haha
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-binlog.000012
          Read_Master_Log_Pos: 1059
               Relay_Log_File: client-relay-bin.000004
                Relay_Log_Pos: 1280
        Relay_Master_Log_File: master-binlog.000012
             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: 1059
              Relay_Log_Space: 2569
              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: 135
                  Master_UUID: 1f502a0e-aad5-11e8-af9c-000c2913cc69
             Master_Info_File: /opt/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for moupdates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 1f502a0e-aad5-11e8-af9c-000c2913cc69:1-6
            Executed_Gtid_Set: 1f502a0e-aad5-11e8-af9c-000c2913cc69:1-6,
e0b213d6-e623-11e8-a2b6-000c290cf8d2:1
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

验证主从同步

mysql> create database ls;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| ls                 |
+--------------------+
6 rows in set (0.00 sec)

在cong上查看

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| ls                 |
+--------------------+
6 rows in set (0.00 sec)

猜你喜欢

转载自blog.csdn.net/qq_26553835/article/details/84063031