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

  • 主数据库
  1. mysql> SHOW MASTER STATUS;
  2. +------------------+----------+--------------+------------------+-------------------------------------------+
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  4. +------------------+----------+--------------+------------------+-------------------------------------------+
  5. | mysql-bin.000002 | 4062 | | | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 |
  6. +------------------+----------+--------------+------------------+-------------------------------------------+
  7. 1 row in set (0.00 sec)
  8. mysql> show global variables like '%gtid%';
  9. +----------------------------------+-------------------------------------------+
  10. | Variable_name | Value |
  11. +----------------------------------+-------------------------------------------+
  12. | binlog_gtid_simple_recovery | ON |
  13. | enforce_gtid_consistency | ON |
  14. | gtid_executed | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 |
  15. | gtid_executed_compression_period | 1000 |
  16. | gtid_mode | ON |
  17. | gtid_owned | |
  18. | gtid_purged | |
  19. | session_track_gtids | OFF |
  20. +----------------------------------+-------------------------------------------+
  21. 8 rows in set (0.00 sec)
  1. # mysqlbinlog mysql-bin.000002
  2. /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
  3. /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
  4. DELIMITER /*!*/;
  5. # at 4
  6. #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
  7. # Warning: this binlog is either in use or was not closed properly.
  8. ROLLBACK/*!*/;
  9. BINLOG '
  10. BWv6ZQ8UAkPAdwAAAHsAAAABAAQANS43LjM5LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  11. AAAAAAAAAAAAAAAAAAAFa/plEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
  12. AULZ7j4=
  13. '/*!*/;
  14. # at 123
  15. #240320 12:50:13 server id 3225616916 end_log_pos 154 CRC32 0xaa49709d Previous-GTIDs
  16. # [empty]
  17. # at 154
  18. #240320 12:50:15 server id 3225616916 end_log_pos 219 CRC32 0xcc611e3e GTID last_committed=0 sequence_number=1 rbr_only=no
  19. SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1'/*!*/;
  20. ...
  21. ...
  22. ...
  23. # at 3200
  24. #240320 12:50:15 server id 3225616916 end_log_pos 3434 CRC32 0xeb895228 Query thread_id=2 exec_time=0 error_code=0
  25. SET TIMESTAMP=1710910215/*!*/;
  26. GRANT SELECT, INSERT, CREATE, RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT, CREATE TABLESPACE ON *.* TO 'bkpuser'@'%'
  27. /*!*/;
  28. # at 3434
  29. #240320 12:50:15 server id 3225616916 end_log_pos 3499 CRC32 0x8ef83223 GTID last_committed=14 sequence_number=15 rbr_only=no
  30. SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:15'/*!*/;
  31. # at 3499
  32. #240320 12:50:15 server id 3225616916 end_log_pos 3689 CRC32 0xdca92acb Query thread_id=2 exec_time=0 error_code=0
  33. SET TIMESTAMP=1710910215/*!*/;
  34. CREATE USER 'proxy_sql_user'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*31C6AAAA2E813546EF9E161596C267B66629F00E'
  35. /*!*/;
  36. # at 3689
  37. #240320 12:50:15 server id 3225616916 end_log_pos 3754 CRC32 0xb97d3937 GTID last_committed=15 sequence_number=16 rbr_only=no
  38. SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:16'/*!*/;
  39. # at 3754
  40. #240320 12:50:15 server id 3225616916 end_log_pos 3910 CRC32 0x7280f9cc Query thread_id=2 exec_time=0 error_code=0
  41. SET TIMESTAMP=1710910215/*!*/;
  42. GRANT ALL PRIVILEGES ON *.* TO 'proxy_sql_user'@'%' WITH GRANT OPTION
  43. /*!*/;
  44. # at 3910
  45. #240320 12:50:15 server id 3225616916 end_log_pos 3975 CRC32 0xf79946ef GTID last_committed=16 sequence_number=17 rbr_only=no
  46. SET @@SESSION.GTID_NEXT= '53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:17'/*!*/;
  47. # at 3975
  48. #240320 12:50:15 server id 3225616916 end_log_pos 4062 CRC32 0x15c4ea73 Query thread_id=2 exec_time=0 error_code=0
  49. SET TIMESTAMP=1710910215/*!*/;
  50. SET @@session.time_zone='SYSTEM'/*!*/;
  51. flush privileges
  52. /*!*/;
  53. SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
  54. DELIMITER ;
  55. # End of log file
  56. /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
  57. /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
  • 从数据库
  1. mysql> SHOW SLAVE STATUS\G
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.67.2.20
  5. Master_User: cdbsync
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000002
  9. Read_Master_Log_Pos: 4062
  10. Relay_Log_File: mysqlseca208g-mysql-master-2-11c17-0-relay-bin.000002
  11. Relay_Log_Pos: 4275
  12. Relay_Master_Log_File: mysql-bin.000002
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 4062
  25. Relay_Log_Space: 4513
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 3225616916
  43. Master_UUID: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8
  44. Master_Info_File: mysql.slave_master_info
  45. SQL_Delay: 0
  46. SQL_Remaining_Delay: NULL
  47. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  48. Master_Retry_Count: 86400
  49. Master_Bind:
  50. Last_IO_Error_Timestamp:
  51. Last_SQL_Error_Timestamp:
  52. Master_SSL_Crl:
  53. Master_SSL_Crlpath:
  54. Retrieved_Gtid_Set: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17
  55. Executed_Gtid_Set: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17
  56. Auto_Position: 1
  57. Replicate_Rewrite_DB:
  58. Channel_Name:
  59. Master_TLS_Version:
  60. 1 row in set (0.00 sec)
  61. mysql> show global variables like '%gtid%';
  62. +----------------------------------+-------------------------------------------+
  63. | Variable_name | Value |
  64. +----------------------------------+-------------------------------------------+
  65. | binlog_gtid_simple_recovery | ON |
  66. | enforce_gtid_consistency | ON |
  67. | gtid_executed | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-17 |
  68. | gtid_executed_compression_period | 1000 |
  69. | gtid_mode | ON |
  70. | gtid_owned | |
  71. | gtid_purged | |
  72. | session_track_gtids | OFF |
  73. +----------------------------------+-------------------------------------------+
  74. 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库,查看从库同步状态

  • 主库
  1. mysql> CREATE DATABASE TEST;
  2. Query OK, 1 row affected (0.00 sec)
  3. mysql> SHOW DATABASES;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | TEST |
  9. | mysql |
  10. | performance_schema |
  11. | sys |
  12. +--------------------+
  13. 5 rows in set (0.00 sec)
  14. mysql> SHOW MASTER STATUS;
  15. +------------------+----------+--------------+------------------+-------------------------------------------+
  16. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  17. +------------------+----------+--------------+------------------+-------------------------------------------+
  18. | mysql-bin.000002 | 4221 | | | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18 |
  19. +------------------+----------+--------------+------------------+-------------------------------------------+
  20. 1 row in set (0.00 sec)
  21. mysql> show global variables like '%gtid%';
  22. +----------------------------------+-------------------------------------------+
  23. | Variable_name | Value |
  24. +----------------------------------+-------------------------------------------+
  25. | binlog_gtid_simple_recovery | ON |
  26. | enforce_gtid_consistency | ON |
  27. | gtid_executed | 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18 |
  28. | gtid_executed_compression_period | 1000 |
  29. | gtid_mode | ON |
  30. | gtid_owned | |
  31. | gtid_purged | |
  32. | session_track_gtids | OFF |
  33. +----------------------------------+-------------------------------------------+
  34. 8 rows in set (0.00 sec)
  • 从库

    从库的Retrieved_Gtid_Set、Executed_Gtid_Set均是53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18,和主库一致。
  1. mysql> SHOW SLAVE STATUS\G
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.67.2.20
  5. Master_User: cdbsync
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000002
  9. Read_Master_Log_Pos: 4221
  10. Relay_Log_File: mysqlseca208g-mysql-master-2-11c17-0-relay-bin.000002
  11. Relay_Log_Pos: 4434
  12. Relay_Master_Log_File: mysql-bin.000002
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 4221
  25. Relay_Log_Space: 4672
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 3225616916
  43. Master_UUID: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8
  44. Master_Info_File: mysql.slave_master_info
  45. SQL_Delay: 0
  46. SQL_Remaining_Delay: NULL
  47. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  48. Master_Retry_Count: 86400
  49. Master_Bind:
  50. Last_IO_Error_Timestamp:
  51. Last_SQL_Error_Timestamp:
  52. Master_SSL_Crl:
  53. Master_SSL_Crlpath:
  54. Retrieved_Gtid_Set: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18
  55. Executed_Gtid_Set: 53e34b1a-e675-11ee-bd7e-fa163e6a9cd8:1-18
  56. Auto_Position: 1
  57. Replicate_Rewrite_DB:
  58. Channel_Name:
  59. Master_TLS_Version:
  60. 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. Nebula Graph 源码解读系列 | Vol.01 Nebula Graph Overview

    上篇序言中我们讲述了源码解读系列的由来,在 Nebula Graph Overview 篇中我们将带你了解下 Nebula Graph 的架构以及代码仓分布.代码结构和模块规划. 1. 架构 Nebu ...

  2. 用CFF Explorer隐藏文件格式

    1.首先我们加载两个PNG文件,可以看到 文件格式头部是一样的,我们如何将一个PDF文件格式改成PNG,修改之后的文件虽然含有图片的文件头格式,但是并不能打开. 将PNG的文件头复制写入到PDF文件头 ...

  3. Spring5课堂笔记

    Spring5 1..Spring 1.1.简介 Spring --> 春天,为开源软件带来了春天 2002,首次推出了Spring框架的雏形:interface21框架! Spring框架以i ...

  4. Java实现书城项目(增删)

    书城项目 登录 dao 接口:UserDao Users login(String username,String password); 实现:UserDaoImpl QueryRunner quer ...

  5. 将本地文件上传到github仓库

    将本地文件上传到github空仓库 本地使用git上传文件: 第一步:在需要的文件夹(文件夹里已经放了需要提交的内容)右击git bash,输入git init 第二步:将本地文件上传到本地git仓库 ...

  6. idea vue 格式化 并保存文件 宏 快捷键 ctrl+s

    idea 格式化是 reformat Code 存盘是 ctrl+s 所以创建一个宏,先点格式化,再点存盘,然后定义个ctrl+s的快捷键覆盖之前的保存就ok了. 资料: IDEA 配置宏定义 并为宏 ...

  7. Springboot K8s Job 一次性任务 如何禁用端口监听

    问题:SpringBoot一次性任务执行时,也会默认监听服务端口,当使用k8s job运行时,可能多个pod执行存在端口冲突 解决办法:命令行禁用SpringBoot一次性任务启动时端口占用 java ...

  8. 2023山东省“技能兴鲁”职业技能大赛-学生组初赛wp

    PWN pwn1 c++ pwn,cin 直接相当于 gets 了,程序有后门,保护基本没开,在 change 的最后一个输入点改掉返回地址为后门地址即可 from pwn import * cont ...

  9. Sub-process /usr/bin/dpkg returned an error code (1)问题

    在用apt-get安装软件包的时候遇到E: Sub-process /usr/bin/dpkg returned an error code (1)问题,解决方法如下: cd /var/lib/dpk ...

  10. 【stars-one】B站视频下载通

    一键下载B站的普通视频.番剧.电影的小工具 获取软件 由于软件还未完善,目前打赏价定位5.88元,后面软件完善价格会提高 >>>点击跳转打赏页面 目前Android版还在开发中 电脑 ...