mysql级联复制_MySQL系列详解九:MySQL级联复制演示-技术流ken

前言

级联复制就是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 |

+---------------------------------+--------------------------------------------+

5 rows in set (0.01 sec)

创建用于复制的用户

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

查看主服务器端状态

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

mysql>show master status\G*************************** 1. row ***************************File: mysql-bin.000012Position:2057Binlog_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)

配置从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_file=2057;

查看连接状态

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

ySQL [(none)]>show slave status\G*************************** 1. row ***************************Slave_IO_State: Waitingfor master to send eventMaster_Host:10.220.5.137Master_User: ken

Master_Port:3306Connect_Retry:60Master_Log_File: mysql-bin.000012Read_Master_Log_Pos:2057Relay_Log_File: relay-bin.000012Relay_Log_Pos:1586Relay_Master_Log_File: mysql-bin.000012Slave_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:0Last_Error:

Skip_Counter:0Exec_Master_Log_Pos:2057Relay_Log_Space:1834Until_Condition: None

Until_Log_File:

Until_Log_Pos:0Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No

Last_IO_Errno:0Last_IO_Error:

Last_SQL_Errno:0Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id:1003306Master_UUID: 987ac782-d7b8-11e8-a462-000c292218ec

Master_Info_File:/data/mysql/mysql3306/data/master.info

SQL_Delay:0SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waitingformore updates

Master_Retry_Count:86400Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:8-13Executed_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:1-13,

c01b1811-d7b3-11e8-8698-000c29492f7b:1-7Auto_Position:0Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:1 row in set (0.00 sec)

查看从1服务器端状态

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

mysql>show master status\G

*************************** 1. row ***************************File: mysql-bin.000007Position: 2057Binlog_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_file=2057;

查看连接状态

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

ySQL [(none)]>show slave status\G*************************** 1. row ***************************Slave_IO_State: Waitingfor master to send eventMaster_Host:10.220.5.138Master_User: ken

Master_Port:3306Connect_Retry:60Master_Log_File: mysql-bin.000007Read_Master_Log_Pos:2057Relay_Log_File: relay-bin.000007Relay_Log_Pos:1586Relay_Master_Log_File: mysql-bin.000007Slave_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:0Last_Error:

Skip_Counter:0Exec_Master_Log_Pos:2057Relay_Log_Space:1834Until_Condition: None

Until_Log_File:

Until_Log_Pos:0Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert: No

Last_IO_Errno:0Last_IO_Error:

Last_SQL_Errno:0Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id:1003306Master_UUID: 987ac782-d7b8-11e8-a462-000c292218ec

Master_Info_File:/data/mysql/mysql3306/data/master.info

SQL_Delay:0SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waitingformore updates

Master_Retry_Count:86400Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:8-13Executed_Gtid_Set: 987ac782-d7b8-11e8-a462-000c292218ec:1-13,

c01b1811-d7b3-11e8-8698-000c29492f7b:1-7Auto_Position:0Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:1 row in set (0.00 sec)

测试

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

主服务器建库建表

mysql>create database ken6; <

mysql>use ken6; <

Database changedmysql> create table ken(id int); <

Query OK,0 rows affected (0.02sec)

mysql> insert into ken values (1),(2); <

Query OK,2 rows affected (0.01sec)

Records:2 Duplicates: 0 Warnings: 0mysql> select * fromken; <

| id |

+------+

| 1 |

| 2 |

+------+

2 rows in set (0.00 sec)

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

MySQL [(none)]> select * fromken6.ken;+------+

| id |

+------+

| 1 |

| 2 |

+------+

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

MySQL [(none)]> select * fromken6.ken;+------+

| id |

+------+

| 1 |

| 2 |

+------+

2 rows in set (0.00 sec)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值