实验环境:

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. 枚举类型的数据存入到map中

    阅读更多 原文来自http://fokman.iteye.com/blog/1568905 public enum IdeasCMD { RESERVED(0), PING(1), PING_ACK( ...

  2. Python深入:Distutils安装包

    一:简介 尽管Python标准库已经支持很多的功能,但是有时还是会需要以第三方模块的形式添加新的功能到Python中. 在最简单的场景中,是你要安装的模块,已经有了针对你的平台的安装版本,因此只需要像 ...

  3. 消息点击率翻倍的背后——闲鱼无侵入可扩展IFTTT系统

    一.面临问题 在闲鱼生态里,用户之间会有很多种关系.其中大部分关系是由买家触发,联系到卖家,比如买家通过搜索.收藏.聊天等动作与卖家产生联系:另外一部分是平台与用户之间的关系.对这些关系分析之后我们发 ...

  4. 模板—v-dcc缩点

    int dfn[MAXN],low[MAXN],num,root; int stack[MAXN],top,cnt; bool iscut[MAXN]; int new_id[MAXN],c[MAXN ...

  5. Android Studio(九):引用jar及so文件

    Android Studio相关博客: Android Studio(一):介绍.安装.配置 Android Studio(二):快捷键设置.插件安装 Android Studio(三):设置Andr ...

  6. Activiti快速入门项目-kft-activiti-demo

    1.项目简介 1.1 项目信息 本项目旨在让Activiti初学者可以快速入门,使用工作流里面的请假流程作为Activiti企业实战的Hello World. 简单通过这个实例说明如何结合流程与业务, ...

  7. ifram子页面与父页面的方法相互调用

    parent.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  8. torch.optim优化算法理解之optim.Adam()

    torch.optim是一个实现了多种优化算法的包,大多数通用的方法都已支持,提供了丰富的接口调用,未来更多精炼的优化算法也将整合进来. 为了使用torch.optim,需先构造一个优化器对象Opti ...

  9. 【t079】火星上的加法运算

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 最近欢欢看到一本有关火星的书籍,其中她被一个加法运算所困惑,由于她的运算水平有限,想向你求助,作为一名 ...

  10. DOM常用操作,Sass基础

    一个元素的子元素个数ParentNode.childElementCount 只读属性返回一个无符号长整型数字,表示给定元素的子元素数. 取消当前事件e.preventDefault();有时候我们选 ...