前言

级联复制就是master服务器,只给后端一台slave服务器同步数据,然后这个slave服务器在向后端的所有slave服务器同步数据,这样就可以降低master服务器的写压力,和复制数据的网络IO。

实现级联复制演示

准备

主服务器IP:10.220.5.137

从1服务器IP:10.220.5.138

从2服务器IP:10.220.5.139

配置主服务器

开启二进制日志

mysql> show global variables like '%log_bin%';
+---------------------------------+--------------------------------------------+
| Variable_name | Value |
+---------------------------------+--------------------------------------------+
| log_bin | ON |
| log_bin_basename | /data/mysql/mysql3306/logs/mysql-bin |
| log_bin_index | /data/mysql/mysql3306/logs/mysql-bin.index |
| log_bin_trust_function_creators | ON |
| log_bin_use_v1_row_events | OFF |
+---------------------------------+--------------------------------------------+
rows in set (0.01 sec)

创建用于复制的用户

mysql> grant replication slave on *.* to 'ken'@'%' identified by 'xx';

查看主服务器端状态

需要查看现在主服务器端在哪个日志文件写入日志以及现在的位置

mysql> show master status\G
*************************** . row ***************************
File: mysql-bin.
Position:
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:-,
c01b1811-d7b3-11e8--000c29492f7b:-
row in set (0.00 sec)

配置从1服务器

与主服务器端建立连接

MySQL [(none)]> change master to master_host='10.220.5.137',master_user='ken',master_passowrd='xx',master_log_file='mysql-bin.000012',master_log_pos=;

启动slave

MySQL [(none)]> start slave;

查看连接状态

要确认IO以及SQL线程成功开启

ySQL [(none)]> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.220.5.137
Master_User: ken
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-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: 987ac782-d7b8-11e8-a462-000c292218ec
Master_Info_File: /data/mysql/mysql3306/data/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: 987ac782-d7b8-11e8-a462-000c292218ec:-
Executed_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:-,
c01b1811-d7b3-11e8--000c29492f7b:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)

查看从1服务器端状态

需要查看现在从1服务器端在哪个日志文件写入日志以及现在的位置

mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000007
Position: 2057
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:1-13,
c01b1811-d7b3-11e8-8698-000c29492f7b:3-7
1 row in set (0.00 sec)

配置从2服务器端

与从1服务器端建立连接

MySQL [(none)]> change master to master_host='10.220.5.138',master_user='ken',master_passowrd='xx',master_log_file='mysql-bin.000007',master_log_pos=2057;

启动slave

MySQL [(none)]> start slave;

查看连接状态

要确认IO以及SQL线程成功开启

ySQL [(none)]> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.220.5.138
Master_User: ken
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-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: 987ac782-d7b8-11e8-a462-000c292218ec
Master_Info_File: /data/mysql/mysql3306/data/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: 987ac782-d7b8-11e8-a462-000c292218ec:-
Executed_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:-,
c01b1811-d7b3-11e8--000c29492f7b:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)

测试

现在从2服务器是从从1服务器端同步的数据,没有直接和主服务器端建立连接,而是通过从1间接的进行了连接。现在在主服务器端建库建表,查看从2服务器是否有主服务器端的库和表。

主服务器建库建表

mysql> create database ken6;              <<建立数据库ken6
mysql> use ken6; <<切换至ken6
Database changed
mysql> create table ken(id int); <<创建表ken
Query OK, rows affected (0.02 sec) mysql> insert into ken values (),(); <<插入数据
Query OK, rows affected (0.01 sec)
Records: Duplicates: Warnings: mysql> select * from ken; <<查看刚才插入的数据
+------+
| id |
+------+
| |
| |
+------+
rows in set (0.00 sec)

在从1服务器端查看已经同步过来了主服务器端新建的库和表

MySQL [(none)]> select * from ken6.ken;
+------+
| id |
+------+
| |
| |
+------+

在从2检查发现也已经同步过来了主服务器端的库和表,这样就完后了级联复制的操作

MySQL [(none)]> select * from ken6.ken;
+------+
| id |
+------+
| |
| |
+------+
rows in set (0.00 sec)

MySQL系列详解九:MySQL级联复制演示-技术流ken的更多相关文章

  1. MySQL系列详解八:MySQL多线程复制演示-技术流ken

    前言 Mysql 采用多线程进行复制是从 Mysql 5.6 开始支持的内容,但是 5.6 版本下有缺陷,虽然支持多线程,但是每个数据库只能一个线程,也就是说如果我们只有一个数据库,则主从复制时也只有 ...

  2. MySQL系列详解十:MySQL多源复制演示-技术流ken

    前言 多源复制即多主一从结构,多个主服务器端的数据都会同步到后端一个从服务器上面.至于为什么要做多源复制下面的总结很到位. 1.灾备作用:将各个库汇总在一起,就算是其他库都挂了(整个机房都无法连接了) ...

  3. MySQL系列详解六:MySQL主从复制/半同步演示-技术流ken

    前言 随着技术的发展,在实际的生产环境中,由单台MySQL数据库服务器不能满足实际的需求.此时数据库集群就很好的解决了这个问题了.采用MySQL分布式集群,能够搭建一个高并发.负载均衡的集群服务器.在 ...

  4. MySQL系列详解三:MySQL中各类日志详解-技术流ken

    前言 日志文件记录了MySQL数据库的各种类型的活动,MySQL数据库中常见的日志文件有 查询日志,慢查询日志,错误日志,二进制日志,中继日志 .下面分别对他们进行介绍. 查询日志 1.查看查询日志变 ...

  5. MySQL系列详解二:MySQL语句操作-技术流ken

    简介 本篇博客将详细讲解mysql的一些常用sql语句操作,例如创建数据库,删除数据库,创建表,修改表,删除表,以及简单查询案例. 关于mysql数据中的SQL的大小写问题 1.不区分大小写 1. s ...

  6. MySQL系列详解一:MySQL&&多实例安装-技术流ken

    简介 MySQL是一个真正的多用户.多线程SQL数据库服务器.SQL(结构化查询语言)是世界上最流行的和标准化的数据库语言,它使得存储.更新和存取信息更加容易.MySQL是一个客户机/服务器结构的实现 ...

  7. MySQL系列详解五: xtrabackup实现完全备份及增量备份详解-技术流ken

    xtrabackup简介 xtrabackup是一个用来对mysql做备份的工具,它可以对innodb引擎的数据库做热备.xtrabackup备份和还原速度快,备份操作不会中断正在执行的事务,备份完成 ...

  8. MySQL系列详解七:MySQL双主架构演示-技术流ken

    前言 在企业中,数据库高可用一直是企业的重中之重,中小企业很多都是使用mysql主从方案,一主多从,读写分离等,但是单主存在单点故障,从库切换成主库需要作改动.因此,如果是双主或者多主,就会增加mys ...

  9. MySQL系列详解四:MySQL事务-技术流ken

    MySQL 事务 MySQL 事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数 ...

随机推荐

  1. 20155205 郝博雅 Exp2 后门原理与实践

    20155205 郝博雅 Exp2 后门原理与实践 一.基础问题回答 后门(木马) 专用程序 投放 隐藏(免杀) 启动(自启动.绑定) (1)例举你能想到的一个后门进入到你系统中的可能方式? 答:上学 ...

  2. 下划线“_”在oracle中不是单纯的表示下划线的意思,而是表示匹配单一任何字符!

    [解决办法]1.使用 escape() 函数escape关键字经常用于使某些特殊字符,如通配符:'%','_'转义为它们原来的字符的意义,被定义的转义字符通常使用'\',但是也可以使用其他的符号.例如 ...

  3. Mac下git配置

    1.下载git 2.配置key macdeMacBook-Pro:~ mac$ cd ~/.ssh macdeMacBook-Pro:.ssh mac$ ssh-keygen -t rsa -C &q ...

  4. python opencv 处理文件、摄像头、图形化界面

    转换成RGB import cv2 import numpy as ny img = ny.zeros( ( 3 , 3 ),ny.float32) img=cv2.cvtColor(img,cv2. ...

  5. 《python语言程序设计》_第6章_函数

    # 6.1_引言 程序1: 结果: Sum from 1 to 10 is 55Sum from 20 to 38 is 513Sum from 35 to 50 is 630 程序2: #程序1和2 ...

  6. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  7. 02 of learning python

    01 input输入的是str类型 如果输入的是数字的话,要记得强制转换一下! 02 isdigit() 这个方法是用来检测字符串是否全部由数字组成 str.isdigit() 如果字符串只包含数字则 ...

  8. Python 日常技巧

    jupyter notebook 本地开启jupyter,画图需打开限制:jupyter notebook --NotebookApp.iopub_data_rate_limit=2147483647 ...

  9. Python小练习之寻找101到200之间的素数

    方法1:from math import * def primeNumber(start,end): num = 0 for i in range(start,end): flag = 0 for j ...

  10. 2018年3月24日上海MVP线下技术交流活动简报

    2018年3月24日下午,几位上海MVP自发组织了一次线下的技术交流会,主要由MVP胡浩牵头,我(陈晴阳).刘鑫.朱兴亮和胡浩各自做了一次主题演讲,具体主题是: 陈晴阳:<这还是我认识的Visu ...