mysql主从之配置验证
实验环境:
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主从之配置验证的更多相关文章
- Docker Mysql主从同步配置搭建
Docker Mysql主从同步配置搭建 建立目录 在虚拟机中建立目录,例如路径/home/mysql/master/data,目录结构如下: Linux中 新建文件夹命令:mkdir 文件夹名 返回 ...
- Mysql主从安装配置
Mysql主从安装配置 环境: 主从服务器上的MySQL数据库版本同为5.1.34 主机IP:192.168.0.1 从机IP:192.168.0.2 一. MySQL主服务器配置 1.编辑配置 ...
- mysql主从同步配置(windows环境)
mysql主从同步配置(mysql5.5,windows环境) A主机(作为主服务器)环境:windows8.mysql5.5 ip:192.168.1.100(自己填) B主机(作为从服务器,由 ...
- MySQL主从备份配置实例
转载自:https://www.cnblogs.com/ahaii/p/6307648.html MySQL主从备份配置实例 场景: 1.主服务器192.168.0.225.从服务器192.168.0 ...
- MySQL主从架构配置
MySQL主从架构配置有两台MySQL数据库服务器master和slave,master为主服务器,slave为从服务器,初始状态时,master和slave中的数据信息相同,当master中的数据发 ...
- centos:mysql主从同步配置(2018)
centos:mysql主从同步配置(2018) https://blog.csdn.net/liubo_2016/article/details/82379115 主服务器:10.1.1.144; ...
- mysql主从简单配置
第一步.配置主从,来自于博文 https://www.cnblogs.com/gl-developer/p/6170423.html 下面配置的步骤就直接复制了. 一.准备工作: 1.主从数据库版本最 ...
- MySQL主从备份配置
MySQL主从热备配置 两台服务器的MySQL版本都是5.5.41master:192.168.3.119slave:192.168.3.120 MySQL主服务器配置:1.创建用于备份的用户 gra ...
- mysql主从之配置基本环境
实验环境 master 192.168.132.121 主库 slave 192.168.132.122 从库 一 mysql的使用介绍 1.1 mysql单台服务器特点 缺点 单台服务器如 ...
随机推荐
- This cache store does not support tagging.
用户权限管理系统 https://github.com/Zizaco/entrust 再添加角色的时候... 报了一个错.. BadMethodCallException in Repository. ...
- Kafka数据迁移MaxCompute最佳实践
摘要: 本文向您详细介绍如何使用DataWorks数据同步功能,将Kafka集群上的数据迁移到阿里云MaxCompute大数据计算服务. 前提条件 搭建Kafka集群 进行数据迁移前,您需要保证自己的 ...
- 学习C#泛型
C#泛型详解 C#菜鸟教程 C#中泛型的使用
- [翻译]Python中yield的解释
问题: Python中yield关键字的作用是什么?它做了什么? 例如,我想理解以下代码 def node._get_child_candidates(self, distance, min_dist ...
- 传说中Python最难理解的点|看这完篇就够了(装饰器)
https://mp.weixin.qq.com/s/B6pEZLrayqzJfMtLqiAfpQ 1.什么是装饰器 网上有人是这么评价装饰器的,我觉得写的很有趣,比喻的很形象 每个人都有的内裤主要是 ...
- C++高精度加减乘除模板
其中高精度乘法通过了POJ2389,其他没有测过,不过应该是没有问题的. 其中高精度除法返回一对string,分别表示商和余数. 代码: #include <bits/stdc++.h> ...
- oracle 使用显式的游标(CURSORs)
使用隐式的游标,将会执行两次操作. 第一次检索记录, 第二次检查TOO MANY ROWS 这个exception . 而显式游标不执行第二次操作.
- supersocket新的配置属性 "textEncoding"
在 SuperSocket 1.6 之前的版本, 当你通过Session对象发送文本时, 将文本信息转换成能够通过Socket传输的二进制数据的默认编码是UTF8. 你可以通过设置 Session 的 ...
- windows/Linux/Mac下安装maven,maven作用
Linux下安装maven 1.首先到Maven官网下载安装文件,目前最新版本为3.0.3,下载文件为apache-maven-3.3.9-bin.tar.gz,下载可以使用wget命令: 2.进入下 ...
- JavaScript中判断整数的方法
一.使用取余运算符判断 任何整数都会被1整除,即余数是0.利用这个规则来判断是否是整数. 1 2 3 4 5 function isInteger(obj) { return obj%1 == ...