实验环境:

master  192.168.132.121 主库

slave     192.168.132.122 从库

一 mysql主从复制的配置

1.1 mysql主库给从库复制的权限

  1. mysql> grant replication slave on *.* to 'replication'@'192.168.132.122' identified by ''; #主库需要给从库复制的权限,一般从都有自己的ip,一台从库放开一个ip
  2. ERROR (HY000): MySQL server has gone away
  3. No connection. Trying to reconnect...
  4. Connection id:
  5. Current database: *** NONE ***
  6. Query OK, rows affected, warning (0.01 sec)
  7. mysql> flush privileges;
  8. Query OK, rows affected (0.00 sec)
  9. mysql> reset master;
  10. Query OK, rows affected (0.01 sec)
  11. mysql> show master logs;
  12. +-------------------+-----------+
  13. | Log_name | File_size |
  14. +-------------------+-----------+
  15. | master-bin. | |
  16. +-------------------+-----------+
  17. row in set (0.00 sec)
  18.  
  19. mysql> show binlog events in 'master-bin.000001';
  20. +-------------------+-----+----------------+-----------+-------------+---------------------------------------+
  21. | Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
  22. +-------------------+-----+----------------+-----------+-------------+---------------------------------------+
  23. | master-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
  24. | master-bin. | | Previous_gtids | | | |
  25. +-------------------+-----+----------------+-----------+-------------+---------------------------------------+

1.2 从库使用命令去同步主库的数据

从库使用命令去同步主库。主库ip、主库端口、用户名、密码、binlog文件名、索引

  1. mysql> change master to master_host='192.168.132.121',master_port=,master_user='replication',master_password='',master_log_file='master-bin.000001',master_log_pos=;
  2. Query OK, rows affected, warnings (0.02 sec)
  3.  
  4. mysql> start slave; #开启salve
  5. Query OK, rows affected (0.00 sec)
  6. mysql> show slave status\G;
  7. *************************** . row ***************************
  8. Slave_IO_State: Waiting for master to send event
  9. Master_Host: 192.168.132.121
  10. Master_User: replication
  11. Master_Port:
  12. Connect_Retry:
  13. Master_Log_File: master-bin.
  14. Read_Master_Log_Pos:
  15. Relay_Log_File: relay-log.
  16. Relay_Log_Pos:
  17. Relay_Master_Log_File: master-bin.
  18. Slave_IO_Running: Yes #IO进程
  19. Slave_SQL_Running: Yes #SQL进程
  20. Replicate_Do_DB:
  21. Replicate_Ignore_DB:
  22. Replicate_Do_Table:
  23. Replicate_Ignore_Table:
  24. Replicate_Wild_Do_Table:
  25. Replicate_Wild_Ignore_Table:
  26. Last_Errno:
  27. Last_Error:
  28. Skip_Counter:
  29. Exec_Master_Log_Pos:
  30. Relay_Log_Space:
  31. Until_Condition: None
  32. Until_Log_File:
  33. Until_Log_Pos:
  34. Master_SSL_Allowed: No
  35. Master_SSL_CA_File:
  36. Master_SSL_CA_Path:
  37. Master_SSL_Cert:
  38. Master_SSL_Cipher:
  39. Master_SSL_Key:
  40. Seconds_Behind_Master: 0 #表示延时
  41. Master_SSL_Verify_Server_Cert: No
  42. Last_IO_Errno:
  43. Last_IO_Error:
  44. Last_SQL_Errno:
  45. Last_SQL_Error:
  46. Replicate_Ignore_Server_Ids:
  47. Master_Server_Id:
  48. Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
  49. Master_Info_File: /data/mysql/master.info
  50. SQL_Delay:
  51. SQL_Remaining_Delay: NULL
  52. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  53. Master_Retry_Count:
  54. Master_Bind:
  55. Last_IO_Error_Timestamp:
  56. Last_SQL_Error_Timestamp:
  57. Master_SSL_Crl:
  58. Master_SSL_Crlpath:
  59. Retrieved_Gtid_Set:
  60. Executed_Gtid_Set:
  61. Auto_Position:
  62. Replicate_Rewrite_DB:
  63. Channel_Name:
  64. Master_TLS_Version:
  65. row in set (0.01 sec)

show processlist;   #查看主从同步的进程

  1. 主端:
    mysql> show processlist;
  2. +----+-------------+-----------------------+------+-------------+------+---------------------------------------------------------------+------------------+
  3. | Id | User | Host | db | Command | Time | State | Info |
  4. +----+-------------+-----------------------+------+-------------+------+---------------------------------------------------------------+------------------+
  5. | | root | localhost | NULL | Query | | starting | show processlist |
  6. | | replication | 192.168.132.122: | NULL | Binlog Dump | | Master has sent all binlog to slave; waiting for more updates | NULL |
  7. +----+-------------+-----------------------+------+-------------+------+---------------------------------------------------------------+------------------+
  8. 从端:
  9. mysql> show processlist;
  10. +----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
  11. | Id | User | Host | db | Command | Time | State | Info |
  12. +----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
  13. | | root | localhost | NULL | Query | | starting | show processlist |
  14. | | system user | | NULL | Connect | | Waiting for master to send event | NULL |
  15. | | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL |
  16. +----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+

二 验证

创建库、创建表、增删改查验证同步是否正常,查看binlog日志

2.1 创建库

  1. 主端建库
  2. mysql> create database darren;
  3. Query OK, row affected (0.00 sec)
  4.  
  5. mysql> show databases;
  6. +--------------------+
  7. | Database |
  8. +--------------------+
  9. | information_schema |
  10. | darren |
  11. | mysql |
  12. | performance_schema |
  13. | sys |
  14. +--------------------+
  15. rows in set (0.00 sec)
  16.  
  17. mysql> show master logs;
  18. +-------------------+-----------+
  19. | Log_name | File_size |
  20. +-------------------+-----------+
  21. | master-bin. | |
  22. +-------------------+-----------+
  23. row in set (0.00 sec)
  24.  
  25. mysql> show binlog events in 'master-bin.000001';
  26. +-------------------+-----+----------------+-----------+-------------+---------------------------------------+
  27. | Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
  28. +-------------------+-----+----------------+-----------+-------------+---------------------------------------+
  29. | master-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
  30. | master-bin. | | Previous_gtids | | | |
  31. | master-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
  32. | master-bin. | | Query | | | create database darren |
  33. +-------------------+-----+----------------+-----------+-------------+---------------------------------------+
  34. 从端查看
  35. mysql> show databases;
  36. +--------------------+
  37. | Database |
  38. +--------------------+
  39. | information_schema |
  40. | darren |
  41. | mysql |
  42. | performance_schema |
  43. | sys |
  44. +--------------------+
  45. rows in set (0.00 sec)
  46.  
  47. mysql> show slave status\G;
  48. *************************** . row ***************************
  49. Slave_IO_State: Waiting for master to send event
  50. Master_Host: 192.168.132.121
  51. Master_User: replication
  52. Master_Port:
  53. Connect_Retry:
  54. Master_Log_File: master-bin.000001
  55. Read_Master_Log_Pos: 319 #读到的偏移量,和master查看的偏移相同,数据已经读完,并同步
  56. Relay_Log_File: relay-log.
  57. Relay_Log_Pos:
  58. Relay_Master_Log_File: master-bin.
  59. Slave_IO_Running: Yes
  60. Slave_SQL_Running: Yes
  61. Replicate_Do_DB:
  62. Replicate_Ignore_DB:
  63. Replicate_Do_Table:
  64. Replicate_Ignore_Table:
  65. Replicate_Wild_Do_Table:
  66. Replicate_Wild_Ignore_Table:
  67. Last_Errno:
  68. Last_Error:
  69. Skip_Counter:
  70. Exec_Master_Log_Pos:
  71. Relay_Log_Space:
  72. Until_Condition: None
  73. Until_Log_File:
  74. Until_Log_Pos:
  75. Master_SSL_Allowed: No
  76. Master_SSL_CA_File:
  77. Master_SSL_CA_Path:
  78. Master_SSL_Cert:
  79. Master_SSL_Cipher:
  80. Master_SSL_Key:
  81. Seconds_Behind_Master:
  82. Master_SSL_Verify_Server_Cert: No
  83. Last_IO_Errno:
  84. Last_IO_Error:
  85. Last_SQL_Errno:
  86. Last_SQL_Error:
  87. Replicate_Ignore_Server_Ids:
  88. Master_Server_Id:
  89. Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
  90. Master_Info_File: /data/mysql/master.info
  91. SQL_Delay:
  92. SQL_Remaining_Delay: NULL
  93. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  94. Master_Retry_Count:
  95. Master_Bind:
  96. Last_IO_Error_Timestamp:
  97. Last_SQL_Error_Timestamp:
  98. Master_SSL_Crl:
  99. Master_SSL_Crlpath:
  100. Retrieved_Gtid_Set:
  101. Executed_Gtid_Set:
  102. Auto_Position:
  103. Replicate_Rewrite_DB:
  104. Channel_Name:
  105. Master_TLS_Version:
  106. row in set (0.00 sec)

2.2 其他命令,增删改查验证

  1. 主端查看表为空
  2. mysql> use darren;
  3. Database changed
  4. mysql> show tables;
  5. Empty set (0.00 sec)
  6. 从端也一样
  7. mysql> use darren;
  8. Database changed
  9. mysql> show tables;
  10. Empty set (0.00 sec)
  11. 主端建表
  12. mysql> create table test (id int);
  13. Query OK, rows affected (0.01 sec)
  14.  
  15. mysql> show tables;
  16. +------------------+
  17. | Tables_in_darren |
  18. +------------------+
  19. | test |
  20. +------------------+
  21. row in set (0.00 sec)
  22. 从端查看
  23. mysql> show tables;
  24. +------------------+
  25. | Tables_in_darren |
  26. +------------------+
  27. | test |
  28. +------------------+
  29. 主端插入数据:
  30. mysql> insert into test values ();
  31. Query OK, row affected (0.00 sec)
  32.  
  33. mysql> select * from test;
  34. +------+
  35. | id |
  36. +------+
  37. | |
  38. +------+
  39. 从端:
  40. mysql> select * from test;
  41. +------+
  42. | id |
  43. +------+
  44. | |
  45. +------+
  46. 继续插入数据:
  47. mysql> insert into test values ();
  48. Query OK, row affected (0.00 sec)
  49.  
  50. mysql> insert into test values ();
  51. Query OK, row affected (0.00 sec)
  52.  
  53. mysql> insert into test values ();
  54. Query OK, row affected (0.00 sec)
  55. mysql> show master status;
  56. +-------------------+----------+--------------+------------------+-------------------+
  57. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  58. +-------------------+----------+--------------+------------------+-------------------+
  59. | master-bin. | | | | |
  60. +-------------------+----------+--------------+------------------+-------------------+
  61. 从端
  62. mysql> select * from test;
  63. +------+
  64. | id |
  65. +------+
  66. | |
  67. | |
  68. | |
  69. | |
  70. +------+
  71. rows in set (0.00 sec)
  72.  
  73. mysql> show slave status\G;
  74. *************************** . row ***************************
  75. Slave_IO_State: Waiting for master to send event
  76. Master_Host: 192.168.132.121
  77. Master_User: replication
  78. Master_Port:
  79. Connect_Retry:
  80. Master_Log_File: master-bin.
  81. Read_Master_Log_Pos:
  82. Relay_Log_File: relay-log.
  83. Relay_Log_Pos:
  84. Relay_Master_Log_File: master-bin.
  85. Slave_IO_Running: Yes
  86. Slave_SQL_Running: Yes
  87. Replicate_Do_DB:
  88. Replicate_Ignore_DB:
  89. Replicate_Do_Table:
  90. Replicate_Ignore_Table:
  91. Replicate_Wild_Do_Table:
  92. Replicate_Wild_Ignore_Table:
  93. Last_Errno:
  94. Last_Error:
  95. Skip_Counter:
  96. Exec_Master_Log_Pos:
  97. Relay_Log_Space:
  98. Until_Condition: None
  99. Until_Log_File:
  100. Until_Log_Pos:
  101. Master_SSL_Allowed: No
  102. Master_SSL_CA_File:
  103. Master_SSL_CA_Path:
  104. Master_SSL_Cert:
  105. Master_SSL_Cipher:
  106. Master_SSL_Key:
  107. Seconds_Behind_Master:
  108. Master_SSL_Verify_Server_Cert: No
  109. Last_IO_Errno:
  110. Last_IO_Error:
  111. Last_SQL_Errno:
  112. Last_SQL_Error:
  113. Replicate_Ignore_Server_Ids:
  114. Master_Server_Id:
  115. Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
  116. Master_Info_File: /data/mysql/master.info
  117. SQL_Delay:
  118. SQL_Remaining_Delay: NULL
  119. Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  120. Master_Retry_Count:
  121. Master_Bind:
  122. Last_IO_Error_Timestamp:
  123. Last_SQL_Error_Timestamp:
  124. Master_SSL_Crl:
  125. Master_SSL_Crlpath:
  126. Retrieved_Gtid_Set:
  127. Executed_Gtid_Set:
  128. Auto_Position:
  129. Replicate_Rewrite_DB:
  130. Channel_Name:
  131. Master_TLS_Version:
  132. 主端删除表
  133. mysql> delete from test;
  134. Query OK, rows affected (0.01 sec)
  135. mysql> select * from test;
  136. Empty set (0.00 sec)
  137. 从端:
  138. mysql> select * from test;
  139. Empty set (0.00 sec)
  140. 主端删除库
  141. mysql> drop database darren;
  142. Query OK, row affected (0.01 sec)
  143.  
  144. mysql> show databases;
  145. +--------------------+
  146. | Database |
  147. +--------------------+
  148. | information_schema |
  149. | mysql |
  150. | performance_schema |
  151. | sys |
  152. +--------------------+
  153. 从端:
  154. mysql> show databases;
  155. +--------------------+
  156. | Database |
  157. +--------------------+
  158. | information_schema |
  159. | mysql |
  160. | performance_schema |
  161. | sys |
  162. +--------------------+

基本的配置完成,实现基本的同步功能!

mysql主从之配置验证的更多相关文章

  1. Docker Mysql主从同步配置搭建

    Docker Mysql主从同步配置搭建 建立目录 在虚拟机中建立目录,例如路径/home/mysql/master/data,目录结构如下: Linux中 新建文件夹命令:mkdir 文件夹名 返回 ...

  2. Mysql主从安装配置

    Mysql主从安装配置   环境: 主从服务器上的MySQL数据库版本同为5.1.34 主机IP:192.168.0.1 从机IP:192.168.0.2  一. MySQL主服务器配置 1.编辑配置 ...

  3. mysql主从同步配置(windows环境)

    mysql主从同步配置(mysql5.5,windows环境)   A主机(作为主服务器)环境:windows8.mysql5.5 ip:192.168.1.100(自己填) B主机(作为从服务器,由 ...

  4. MySQL主从备份配置实例

    转载自:https://www.cnblogs.com/ahaii/p/6307648.html MySQL主从备份配置实例 场景: 1.主服务器192.168.0.225.从服务器192.168.0 ...

  5. MySQL主从架构配置

    MySQL主从架构配置有两台MySQL数据库服务器master和slave,master为主服务器,slave为从服务器,初始状态时,master和slave中的数据信息相同,当master中的数据发 ...

  6. centos:mysql主从同步配置(2018)

    centos:mysql主从同步配置(2018) https://blog.csdn.net/liubo_2016/article/details/82379115 主服务器:10.1.1.144; ...

  7. mysql主从简单配置

    第一步.配置主从,来自于博文 https://www.cnblogs.com/gl-developer/p/6170423.html 下面配置的步骤就直接复制了. 一.准备工作: 1.主从数据库版本最 ...

  8. MySQL主从备份配置

    MySQL主从热备配置 两台服务器的MySQL版本都是5.5.41master:192.168.3.119slave:192.168.3.120 MySQL主服务器配置:1.创建用于备份的用户 gra ...

  9. mysql主从之配置基本环境

    实验环境 master  192.168.132.121 主库 slave     192.168.132.122 从库 一 mysql的使用介绍 1.1 mysql单台服务器特点 缺点 单台服务器如 ...

随机推荐

  1. This cache store does not support tagging.

    用户权限管理系统 https://github.com/Zizaco/entrust 再添加角色的时候... 报了一个错.. BadMethodCallException in Repository. ...

  2. Kafka数据迁移MaxCompute最佳实践

    摘要: 本文向您详细介绍如何使用DataWorks数据同步功能,将Kafka集群上的数据迁移到阿里云MaxCompute大数据计算服务. 前提条件 搭建Kafka集群 进行数据迁移前,您需要保证自己的 ...

  3. 学习C#泛型

    C#泛型详解 C#菜鸟教程 C#中泛型的使用

  4. [翻译]Python中yield的解释

    问题: Python中yield关键字的作用是什么?它做了什么? 例如,我想理解以下代码 def node._get_child_candidates(self, distance, min_dist ...

  5. 传说中Python最难理解的点|看这完篇就够了(装饰器)

    https://mp.weixin.qq.com/s/B6pEZLrayqzJfMtLqiAfpQ 1.什么是装饰器 网上有人是这么评价装饰器的,我觉得写的很有趣,比喻的很形象 每个人都有的内裤主要是 ...

  6. C++高精度加减乘除模板

    其中高精度乘法通过了POJ2389,其他没有测过,不过应该是没有问题的. 其中高精度除法返回一对string,分别表示商和余数. 代码: #include <bits/stdc++.h> ...

  7. oracle 使用显式的游标(CURSORs)

    使用隐式的游标,将会执行两次操作. 第一次检索记录, 第二次检查TOO MANY ROWS 这个exception . 而显式游标不执行第二次操作.

  8. supersocket新的配置属性 "textEncoding"

    在 SuperSocket 1.6 之前的版本, 当你通过Session对象发送文本时, 将文本信息转换成能够通过Socket传输的二进制数据的默认编码是UTF8. 你可以通过设置 Session 的 ...

  9. windows/Linux/Mac下安装maven,maven作用

    Linux下安装maven 1.首先到Maven官网下载安装文件,目前最新版本为3.0.3,下载文件为apache-maven-3.3.9-bin.tar.gz,下载可以使用wget命令: 2.进入下 ...

  10. JavaScript中判断整数的方法

    一.使用取余运算符判断 任何整数都会被1整除,即余数是0.利用这个规则来判断是否是整数. 1 2 3 4 5 function isInteger(obj) {     return obj%1 == ...