数据库创建完后主从数据库数据保持同步

  • 主数据库
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------------------------------+
| mysql-bin.000002 | 4062 | | | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 |
+------------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec) mysql> show global variables like '%gtid%';
+----------------------------------+-------------------------------------------+
| Variable_name | Value |
+----------------------------------+-------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-------------------------------------------+
8 rows in set (0.00 sec)
# mysqlbinlog mysql-bin.000002
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#240320 12:50:13 server id 3225616916 end_log_pos 123 CRC32 0x3eeed942 Start: binlog v 4, server v 5.7.39-log created 240320 12:50:13 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
BWv6ZQ8UAkPAdwAAAHsAAAABAAQANS43LjM5LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAFa/plEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AULZ7j4=
'/*!*/;
# at 123
#240320 12:50:13 server id 3225616916 end_log_pos 154 CRC32 0xaa49709d Previous-GTIDs
# [empty]
# at 154
#240320 12:50:15 server id 3225616916 end_log_pos 219 CRC32 0xcc611e3e GTID last_committed=0 sequence_number=1 rbr_only=no
SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1'/*!*/;
...
...
... # at 3200
#240320 12:50:15 server id 3225616916 end_log_pos 3434 CRC32 0xeb895228 Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1710910215/*!*/;
GRANT SELECT, INSERT, CREATE, RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT, CREATE TABLESPACE ON *.* TO 'bkpuser'@'%'
/*!*/;
# at 3434
#240320 12:50:15 server id 3225616916 end_log_pos 3499 CRC32 0x8ef83223 GTID last_committed=14 sequence_number=15 rbr_only=no
SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:15'/*!*/;
# at 3499
#240320 12:50:15 server id 3225616916 end_log_pos 3689 CRC32 0xdca92acb Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1710910215/*!*/;
CREATE USER 'proxy_sql_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*31C6AAAA2E813546EF9E161596C267B66629F00E'
/*!*/;
# at 3689
#240320 12:50:15 server id 3225616916 end_log_pos 3754 CRC32 0xb97d3937 GTID last_committed=15 sequence_number=16 rbr_only=no
SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:16'/*!*/;
# at 3754
#240320 12:50:15 server id 3225616916 end_log_pos 3910 CRC32 0x7280f9cc Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1710910215/*!*/;
GRANT ALL PRIVILEGES ON *.* TO 'proxy_sql_user'@'%' WITH GRANT OPTION
/*!*/;
# at 3910
#240320 12:50:15 server id 3225616916 end_log_pos 3975 CRC32 0xf79946ef GTID last_committed=16 sequence_number=17 rbr_only=no
SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:17'/*!*/;
# at 3975
#240320 12:50:15 server id 3225616916 end_log_pos 4062 CRC32 0x15c4ea73 Query thread_id=2 exec_time=0 error_code=0
SET TIMESTAMP=1710910215/*!*/;
SET @@session.time_zone='SYSTEM'/*!*/;
flush privileges
/*!*/;
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*/;
  • 从数据库
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.67.2.20
Master_User: cdbsync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 4062
Relay_Log_File: mysqlseca208g-mysql-master-2-11c17-0-relay-bin.000002
Relay_Log_Pos: 4275
Relay_Master_Log_File: mysql-bin.000002
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: 4062
Relay_Log_Space: 4513
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: 3225616916
Master_UUID: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8
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: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17
Executed_Gtid_Set: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec) mysql> show global variables like '%gtid%';
+----------------------------------+-------------------------------------------+
| Variable_name | Value |
+----------------------------------+-------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-------------------------------------------+
8 rows in set (0.00 sec)
参数 主库 从库
Executed_Gtid_Set 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17
binlog文件名称 mysql-bin.000002 mysql-bin.000002( Relay_Master_Log_File)
Position 4062 4062(Read_Master_Log_Pos)
Exec_Master_Log_Pos 4062

主库创建一个TEST库,查看从库同步状态

  • 主库
mysql> CREATE DATABASE TEST;
Query OK, 1 row affected (0.00 sec) mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| TEST |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec) mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------------------------------+
| mysql-bin.000002 | 4221 | | | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18 |
+------------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec) mysql> show global variables like '%gtid%';
+----------------------------------+-------------------------------------------+
| Variable_name | Value |
+----------------------------------+-------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18 |
| gtid_executed_compression_period | 1000 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-------------------------------------------+
8 rows in set (0.00 sec)
  • 从库

    从库的Retrieved_Gtid_Set、Executed_Gtid_Set均是53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18,和主库一致。
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.67.2.20
Master_User: cdbsync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 4221
Relay_Log_File: mysqlseca208g-mysql-master-2-11c17-0-relay-bin.000002
Relay_Log_Pos: 4434
Relay_Master_Log_File: mysql-bin.000002
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: 4221
Relay_Log_Space: 4672
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: 3225616916
Master_UUID: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8
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: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18
Executed_Gtid_Set: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)

Mysql之主从异步的更多相关文章

  1. Mysql数据库主从心得整理

    管理mysql主从有2年多了,管理过200多组mysql主从,几乎涉及到各个版本的主从,本博文属于总结性的,有一部分是摘自网络,大部分是根据自己管理的心得和经验所写,整理了一下,分享给各位同行,希望对 ...

  2. MySQL Replication, 主从和双主配置

    MySQL Replication, 主从和双主配置 MySQL的Replication是一种多个MySQL的数据库做主从同步的方案,特点是异步,广泛用在各种对MySQL有更高性能,更高可靠性要求的场 ...

  3. (转)Mysql数据库主从心得整理

    Mysql数据库主从心得整理 原文:http://blog.sae.sina.com.cn/archives/4666 管理mysql主从有2年多了,管理过200多组mysql主从,几乎涉及到各个版本 ...

  4. MySQL数据库主从同步延迟分析及解决方案

    一.MySQL的数据库主从复制原理 MySQL主从复制实际上基于二进制日志,原理可以用一张图来表示: 分为四步走: 1. 主库对所有DDL和DML产生的日志写进binlog: 2. 主库生成一个 lo ...

  5. MySQL之主从同步

    一.主从同步概念 1.1 什么是主从同步? MySQL 主从同步是指将数据从一个 MySQL 数据库服务器主节点复制到一个或多个从节点.MySQL 默认采用异步复制方式,这样从节点不用一直访问主服务器 ...

  6. MySQL主从复制之异步模式

    MySQL主从复制有异步模式.半同步模式.GTID模式以及多源复制模式,MySQL默认模式是异步模式.所谓异步模式,只MySQL 主服务器上I/O thread 线程将二进制日志写入binlog文件之 ...

  7. mysql数据库主从同步

    环境: Mater:   CentOS7.1  5.5.52-MariaDB  192.168.108.133 Slave:   CentOS7.1  5.5.52-MariaDB  192.168. ...

  8. [转]向facebook学习,通过协程实现mysql查询的异步化

    FROM : 通过协程实现mysql查询的异步化 前言 最近学习了赵海平的演讲,了解到facebook的mysql查询可以进行异步化,从而提高性能.由于facebook实现的比较早,他们不得不对php ...

  9. mysql mha 主从自动切换 高可用

    mha(Master High Availability)目前在MySQL多服务器(超过二台),高可用方面是一个相对成熟的解决方案. 一,什么是mha,有什么特性 1. 主服务器的自动监控和故障转移 ...

  10. Mysql的主从数据库没有同步的解决办法

    Mysql的主从数据库没有同步的解决办法 今天发现Mysql的主从数据库没有同步 先上Master库: mysql>show processlist; 查看下进程是否Sleep太多.发现很正常. ...

随机推荐

  1. Big-Yellow的算法工程师进阶之路

    Big-Yellow的算法工程师进阶之路 一.基础算法 二.基础数据结构 2.1 链表[1] 2.1.1 基础理论 链表是一种以链的形式来存储数据的数据结构.链表的结构:每一个数据都与其后一个数据相连 ...

  2. Mysql基础目录

    尚硅谷Mysql课程笔记 课程链接: https://www.bilibili.com/video/BV1iq4y1u7vj?p=1 第01章_数据库概述 第02章_MySQL环境搭建 第03章_基本 ...

  3. 1、eureka的注册流程

    客户端注册到服务端是通过http请求的 涉及到多级缓存 register注册表 源码精髓:多级缓存设计思想 在拉取注册表的时候: 首先从ReadOnlyCacheMap里查缓存的注册表. 若没有,就找 ...

  4. 子序列&子串

    子序列:子序列就是在原来序列中找出一部分组成的序列 子序列不一定连续 子串:字符串中任意个连续的字符组成的子序列称为该串的子串 子串一定连续

  5. C语言趣味编程之三天打鱼两天晒网

    include <stdio.h> typedef struct date {//定义一个日期结构体date,三个成员变量year\month\day,使得年月日作为一个整体,相互联系. ...

  6. 在vue3中使用openlayers3实现track轨迹动画

    网上太多资料代码,抄来抄去,而且版本也是v5.x版本的,部分API已经弃用 基础知识不多说,直接讲重点 三个关键变量 // 记录开始动画的时间 const startTime = ref(0); // ...

  7. 网络流与各种建模(I)

    网络流与各种建模(I) 网络流基础 这里默认读者学习过网络流和MCMF,这里仅作复习 网络流解决的问题是给一个源点和汇点,每个边有最大流量,最大化从源点放水到汇点的速率. 网络流的时间复杂度是 \(O ...

  8. Xmind 括号图 风格不错,挺好看的

    Xmind 括号图 风格不错,挺好看的 之前没注意到呢~ 又搞了个竖屏的,竖屏的关键点是 先隐藏第一层包括线,然后线就全部隐藏了,然后再选择要显示线的那部分,让线显示就ok了.

  9. t w 不连读,只不过离得很近 twins twelve 单词发音

    t w 不连读,只不过离得很近 twins twelve

  10. python 文件操作常用方法

    一 python文件创建 import os import argparse def file_write(file_name,msg): f = open(file_name,"a&quo ...