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单台服务器特点 缺点 单台服务器如 ...
随机推荐
- HDU 5673 Robot【卡特兰数】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 题意: 有一个机器人位于坐标原点上.每秒钟机器人都可以向右移到一个单位距离,或者在原地不动.如 ...
- OpenCV 新手教程 之环境配置 + 图片匹配 matchTemplate
1.什么是OpenCV OpenCV的全称是:Open Source Computer Vision Library. OpenCV是一个基于(开源)发行的跨平台计算机视觉库,能够执行在Linux.W ...
- SDUT-3340_数据结构实验之二叉树一:树的同构
数据结构实验之二叉树一:树的同构 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定两棵树T1和T2.如果T1可以通过 ...
- qt 利用Qtimer 定时器实现定时消息发送
为了实现给控制器按周期发送控制指令,利用qt中的Qtimer 实现消息的定时发送. 需要进行三步处理: 1.在mainwindow.h文件中对timerEvent进行声明 public virtual ...
- java 根据秘钥,对数据进行加解密
package test; import com.alibaba.fastjson.JSONObject; import sun.misc.BASE64Decoder; import sun.misc ...
- 洛谷P1164 小A点菜
//求方案数 定义状态f[i][j] 用前i件物品恰好放够体积为j的背包 方案数 #include<bits/stdc++.h> using namespace std; ; ; int ...
- List of the best open source software applications
List of the best open source software applications by Ryan • Oct 25th, 2008 • Category: Featured Art ...
- Laravel5.2 发送邮件(smtp方式最简单的讲解!)-邮件部分
https://blog.csdn.net/wulove52/article/details/71172842 Laravel集成了SwiftMailer库进行邮件发送,邮件配置文件位于config/ ...
- 洛谷P4018 Roy&October之取石子 题解 博弈论
题目链接:https://www.luogu.org/problem/P4018 首先碰到这道题目还是没有思路,于是寻思还是枚举找一找规律. 然后写了一下代码: #include <bits/s ...
- 5分钟了解为什么学习Go
1.什么是Go语言? Google开源 编译型语言 21世纪的C语言(主流编程语言都是单线程环境下发布的) 2.Go语言的特点? 简单易学习(类似python学习难度,自带格式化) 开发效率高 执行性 ...