续: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来对日志就行回放

相关推荐
九零HTTP1 小时前
10月21号-CSDN配菜-IP池的5个坑
服务器·数据库·tcp/ip
Data-Miner1 小时前
需要做财务数据分析,有什么好用的工具?从准备到出报告的实操指南
大数据·数据库·数据分析
袋鼠云数栈2 小时前
让 SQL 解析不再重复造轮子:SqlParserX 正式开源
数据库·人工智能·sql·开源·数据治理
这个DBA有点耶2 小时前
期货 CTP 系统 Oracle RAC 迁移国产库实战:读写分离架构设计与性能对标
数据库·架构·dba
数据库安全2 小时前
AI数据访问安全 |如何控制AI访问权限,防止越权
数据库·安全
小羊没烦恼!3 小时前
异步编程:线程概述及使用
java·开发语言·mysql·算法·c#
这个DBA有点耶3 小时前
Redo Log循环写与checkpoint推进:长事务阻塞下的Checkpoint风暴完整链路
数据库·mysql·代码规范
jnrjian3 小时前
pg_waldump --key-file-name status 查看wal 产生的db
数据库
SelectDB技术团队4 小时前
Snowflake 的开源替代怎么选:能力对照、三条部署路径与迁移执行
大数据·数据库·云原生·开源·snowflake·apache doris
Elastic 中国社区官方博客4 小时前
告别繁琐控制台:Kabanos 如何将 MongoDB Compass 的易用性带入 Elasticsearch
大数据·数据库·mongodb·elasticsearch·搜索引擎·全文检索