实验环境:

master  192.168.132.121 主库

slave     192.168.132.122 从库

一 mysql主从复制的配置

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

mysql> grant replication slave on *.* to 'replication'@'192.168.132.122' identified by '';   #主库需要给从库复制的权限,一般从都有自己的ip,一台从库放开一个ip
ERROR (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:
Current database: *** NONE ***
Query OK, rows affected, warning (0.01 sec)
mysql> flush privileges;
Query OK, rows affected (0.00 sec)
mysql> reset master;
Query OK, rows affected (0.01 sec)
mysql> show master logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin. | |
+-------------------+-----------+
row in set (0.00 sec) mysql> show binlog events in 'master-bin.000001';
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
| master-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
| master-bin. | | Previous_gtids | | | |
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+

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

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

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=;
Query OK, rows affected, warnings (0.02 sec) mysql> start slave; #开启salve
Query OK, rows affected (0.00 sec)
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.121
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes #IO进程
Slave_SQL_Running: Yes #SQL进程
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
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:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
Master_Info_File: /data/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.01 sec)

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

主端:
mysql> show processlist;
+----+-------------+-----------------------+------+-------------+------+---------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------------------+------+-------------+------+---------------------------------------------------------------+------------------+
| | root | localhost | NULL | Query | | starting | show processlist |
| | replication | 192.168.132.122: | NULL | Binlog Dump | | Master has sent all binlog to slave; waiting for more updates | NULL |
+----+-------------+-----------------------+------+-------------+------+---------------------------------------------------------------+------------------+
从端:
mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+
| | root | localhost | NULL | Query | | starting | show processlist |
| | system user | | NULL | Connect | | Waiting for master to send event | NULL |
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+

二 验证

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

2.1 创建库

主端建库
mysql> create database darren;
Query OK, row affected (0.00 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| darren |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) mysql> show master logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin. | |
+-------------------+-----------+
row in set (0.00 sec) mysql> show binlog events in 'master-bin.000001';
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
| master-bin. | | Format_desc | | | Server ver: 5.7.-log, Binlog ver: |
| master-bin. | | Previous_gtids | | | |
| master-bin. | | Anonymous_Gtid | | | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| master-bin. | | Query | | | create database darren |
+-------------------+-----+----------------+-----------+-------------+---------------------------------------+
从端查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| darren |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec) mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.121
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 319 #读到的偏移量,和master查看的偏移相同,数据已经读完,并同步
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
Master_Info_File: /data/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)

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

主端查看表为空
mysql> use darren;
Database changed
mysql> show tables;
Empty set (0.00 sec)
从端也一样
mysql> use darren;
Database changed
mysql> show tables;
Empty set (0.00 sec)
主端建表
mysql> create table test (id int);
Query OK, rows affected (0.01 sec) mysql> show tables;
+------------------+
| Tables_in_darren |
+------------------+
| test |
+------------------+
row in set (0.00 sec)
从端查看
mysql> show tables;
+------------------+
| Tables_in_darren |
+------------------+
| test |
+------------------+
主端插入数据:
mysql> insert into test values ();
Query OK, row affected (0.00 sec) mysql> select * from test;
+------+
| id |
+------+
| |
+------+
从端:
mysql> select * from test;
+------+
| id |
+------+
| |
+------+
继续插入数据:
mysql> insert into test values ();
Query OK, row affected (0.00 sec) mysql> insert into test values ();
Query OK, row affected (0.00 sec) mysql> insert into test values ();
Query OK, row affected (0.00 sec)
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin. | | | | |
+-------------------+----------+--------------+------------------+-------------------+
从端
mysql> select * from test;
+------+
| id |
+------+
| |
| |
| |
| |
+------+
rows in set (0.00 sec) mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.132.121
Master_User: replication
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 77278e78-9da8-11e9-bc6c-000c2991dd19
Master_Info_File: /data/mysql/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
主端删除表
mysql> delete from test;
Query OK, rows affected (0.01 sec)
mysql> select * from test;
Empty set (0.00 sec)
从端:
mysql> select * from test;
Empty set (0.00 sec)
主端删除库
mysql> drop database darren;
Query OK, row affected (0.01 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
从端:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+

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

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. KiCad EDA 5.1.2 使用圆形板框时出现无法走线的问题

    KiCad EDA 5.1.2 使用圆形板框时出现无法走线的问题 看到官方已经修复,等着官方发布新的版本 5.1.3. Steps to reproduce: 1) create new board. ...

  2. 5、nginx配置

    1.安装 sudo apt-get install nginx 2.启用 sudo service nginx start 3.若要将 Nginx 配置为转发请求向 ASP.NET Core 应用程序 ...

  3. uva 11806 Cheerleaders (容斥)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. 本地运行angularjs应用,提示出现跨域问题

    应用介绍: 使用angularjs创建一个简单的公司员工管理页面 使用Chrome打开后,提示存在跨域问题. 和别人交流后,得知使用像Angular,React,Vue框架,在Chrome地址栏中输入 ...

  5. Windows系统下三十款优秀开源软件

    Windows系统下三十款优秀开源软件 1.Firefox 官方网站:http://www.getfirefox.com/ 可替换Internet Explorer 功能特点:如果你还没有使用Fire ...

  6. JavaScript 鼠标事件

    鼠标事件是Web开发中最常用的一类事件. DOM3级事件中定义了9个鼠标事件,分别如下: click.dbclick.mousedown.mouseenter.mouseleave.mousemove ...

  7. LRJ 3-7

    #define _CRT_SECURE_NO_WARNINGS #include <cstdio> int main() { int T; int m, n; ][]; // 4 < ...

  8. HOSt ip is not allowed to connect to this MySql server, MYSQL添加远程用户或允许远程访问三种方法

    HOSt ip is not allowed to connect to this MySql server 报错:1130-host ... is not allowed to connect to ...

  9. [转]SpringBoot整合Swagger2以及生产环境的安全问题处理

    1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...

  10. hadoop 端口总结

    localhost:50030/jobtracker.jsp localhost:50060/tasktracker.jsp localhost:50070/dfshealth.jsp 1. Name ...