续:MySQL的gtid模式

为什么要启用gtid?

master端和slave端有延迟

##设置gtid

master slave1 slave2

[root@mysql1 ~]# vim /etc/my.cnf

[root@mysql1 ~]# cat /etc/my.cnf

[mysqld]

datadir=/data/mysql

socket=/data/mysql/mysql.sock

symbolic-links=0

log-bin=mysql-bin

server-id=1

slow_query_log=on

gtid_mode=on

enforce-gtid-consistency=on

[root@mysql1 ~]# /etc/init.d/mysqld restart

Shutting down MySQL........ SUCCESS!

Starting MySQL........... SUCCESS!

[root@mysql3 ~]# vim /etc/my.cnf

[root@mysql3 ~]# cat /etc/my.cnf

[mysqld]

datadir=/data/mysql

socket=/data/mysql/mysql.sock

symbolic-links=0

server_id=3

gtid_mode=on

enforce-gtid-consistency=on

[root@mysql3 ~]# systemctl restart mysqld

Failed to restart mysqld.service: Unit not found.

[root@mysql3 ~]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL..... SUCCESS!

把slave1也重启一下

[root@mysql2 ~]# /etc/init.d/mysqld restart

Shutting down MySQL... SUCCESS!

Starting MySQL......... SUCCESS!

#看一下master的日志

[root@mysql1 ~]# mysql -uroot -predhat

mysql> SHOW MASTER STATUS;

+------------------+----------+--------------+------------------+-------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000002 | 154 | | | |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql> exit;

Bye

[root@mysql1 ~]# mysqlbinlog -vv /data/mysql/mysql-bin.000002

/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;

/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;

DELIMITER /*!*/;

at 4

#240827 11:39:36 server id 1 end_log_pos 123 CRC32 0x1aa93b7f Start: binlog v 4, server v 5.7.44-log created 240827 11:39:36 at startup

Warning: this binlog is either in use or was not closed properly.

ROLLBACK/*!*/;

BINLOG '

eErNZg8BAAAAdwAAAHsAAAABAAQANS43LjQ0LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAB4Ss1mEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA

AX87qRo=

'/*!*/;

at 123

#240827 11:39:36 server id 1 end_log_pos 154 CRC32 0x7a75cfb5 Previous-GTIDs

[empty]

SET @@SESSION.GTID_NEXT= 'AUTOMATIC'/* added by mysqlbinlog */ /*!*/;

DELIMITER ; #说明已经开启了

End of log file

/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

#重新设定slave:

#1. 在所有从slave上关掉slave

mysql> stop slave;

Query OK, 0 rows affected (0.01 sec)

#2.

mysql> change master to

-> master_host='172.25.254.6',

-> master_user='repl',

-> master_password='redhat',

-> master_auto_position=1

-> ;

Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> start slave;

Query OK, 0 rows affected (0.08 sec)

mysql> SHOW SLAVE STATUS\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 172.25.254.6

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000002

Read_Master_Log_Pos: 154 #自动识别到了

Relay_Log_File: mysql2-relay-bin.000002

Relay_Log_Pos: 367

Relay_Master_Log_File: mysql-bin.000002

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

.....略

#slave2也同上,只不过遇到点问题

[root@mysql3 ~]# mysql -uroot -predhat

mysql> stop slave;

Query OK, 0 rows affected (0.00 sec)

mysql> change master to

-> master_host='172.25.254.6',

-> master_user='repl',

-> master_password='redhat',

-> master_auto_position=1

-> ;

Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

mysql> SHOW SLAVE STATUS\G;

*************************** 1. row ***************************

Slave_IO_State: Connecting to master

Master_Host: 172.25.254.6

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File:

Read_Master_Log_Pos: 4

Relay_Log_File: mysql3-relay-bin.000001

Relay_Log_Pos: 4

Relay_Master_Log_File:

Slave_IO_Running: Connecting #出现问题,连不上io
Slave_SQL_Running: Yes

...略

mysql> exit;

Bye

##解决

[root@mysql3 ~]# ps aux | grep mysqld

root 57157 0.0 0.0 113412 1588 pts/2 S 11:38 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql3.pid

mysql 57322 0.1 9.1 1144772 170096 pts/2 Sl 11:38 0:07 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql3.err --pid-file=/data/mysql/mysql3.pid --socket=/data/mysql/mysql.sock

root 58302 0.0 0.0 112808 968 pts/2 S+ 13:18 0:00 grep --color=auto mysqld

[root@mysql3 ~]# kill 57322

[root@mysql3 ~]# ps aux | grep mysqld

root 58309 0.0 0.0 112808 968 pts/2 R+ 13:19 0:00 grep --color=auto mysqld

[root@mysql3 ~]# /etc/init.d/mysqld restart

ERROR! MySQL server PID file could not be found!

Starting MySQL. SUCCESS!

[root@mysql3 ~]# mysql -uroot -predhat

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 172.25.254.6

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000002

Read_Master_Log_Pos: 154

Relay_Log_File: mysql3-relay-bin.000004

Relay_Log_Pos: 367

Relay_Master_Log_File: mysql-bin.000002

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

...略

gtid就做好了,用全局的id来对日志就行回放

相关推荐
ROCKY_8174 小时前
Mysql复习(二)
数据库·mysql·oracle
问道飞鱼6 小时前
【知识科普】认识正则表达式
数据库·mysql·正则表达式
HaiFan.6 小时前
SpringBoot 事务
java·数据库·spring boot·sql·mysql
水根LP496 小时前
linux系统上SQLPLUS的重“大”发现
数据库·oracle
途途途途7 小时前
精选9个自动化任务的Python脚本精选
数据库·python·自动化
04Koi.8 小时前
Redis--常用数据结构和编码方式
数据库·redis·缓存
silver98868 小时前
mongodb和Cassandra
数据库
PersistJiao8 小时前
3.基于 Temporal 的 Couchbase 动态 SQL 执行场景
数据库·sql
上山的月8 小时前
MySQL -函数和约束
数据库·mysql
zhcf8 小时前
【MySQL】十三,关于MySQL的全文索引
数据库·mysql