mysql5.7版本gitd主从 mysql

环境
192.168.199.130
192.168.199.131

mysql从5.65版本之后可以使用GTID

安装MySQL5.7版本

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server

配置GTID参数 主
Master参数:

gtid-mode = ON
enforce-gtid-consistency = ON
server-id =100
binlog_format = ROW
log-bin = mysql-bin

Slave上参数配置:

gtid-mode = ON
enforce-gtid-consistency = ON
server-id =200
binlog_format = ROW
log-bin = mysql-bin
log_slave_updates = ON
skip-slave-start = 1

重启mysqld服务

先去获取MySQL本身自带的密码

grep password /var/lib/mysqld.log
后方password

在这里插入图片描述
set password = password(“NTMSsb_123”); 重置密码 退出登录MySQL数据库

二 、在主数据库配置账号

grant replication slave on . to ‘slave’@‘192.168.199.%’ identified by ‘Slave_123’;

flush privileges;

配置从库同步

stop slave;

mysql> CHANGE MASTER TO
MASTER_HOST=‘192.168.10.100’,
MASTER_USER=‘sunfei’,
MASTER_PASSWORD=‘sunfei’,
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;

3、开启同步并查看同步状态

mysql> start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.10.100
Master_User: sunfei
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 918
Relay_Log_File: Client-relay-bin.000004
Relay_Log_Pos: 454
Relay_Master_Log_File: mysql-bin.000001
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: 918
Relay_Log_Space: 962
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: 1003306
Master_UUID: b3f31135-4851-11e8-b758-000c29148b03
Master_Info_File: 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: b3f31135-4851-11e8-b758-000c29148b03:1-4
Executed_Gtid_Set: 25d36cbf-485a-11e8-a621-000c292c6f36:1-3,
b3f31135-4851-11e8-b758-000c29148b03:1-4
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec
参数说明:

Retrieved_Gtid_Set: b3f31135-4851-11e8-b758-000c29148b03:1-4                              #表示收到的事务数
Executed_Gtid_Set: 25d36cbf-485a-11e8-a621-000c292c6f36:1-3,b3f31135-4851-11e8-b758-000c29148b03:1-4      #表示执行完的事务数
当出现主从故障的时候,可以从这里观察具体卡在哪个事务。

跳过事务:

假如主从复制出现错误
当在 slave 上执行 show slave status\G
Retrieved_Gtid_Set: UUID:1-5
Executed_Gtid_Set: UUID:1-4
此时 Slave_SQL_Running: No
上面的信息表明:
slave 收到了 UUID:1-5 个事务,执行成功 UUID:1-4,1-4 表示已经执行完成了。在这里出现了错误,也就是说执行 UUID:1-5时出现了错误。所以我们应该要跳过下一个事务即 5;
解决方法:
按照下列步骤执行

mysql> stop slave;
mysql> set gtid_next=‘UUID:5’;
mysql> begin;
mysql> commit;
mysql> set gtid_next=‘automatic’;
mysql> start slave;
在跳过之前,分析一下 Binlog 并且记录下来,分析是否可以跳过。跳过之后,看一下主从数据是否一致,是否需要修复数据等等。总之,需要具体问题具体分析,请谨慎操作。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值