42-4 mysql主从复制

04 mysql主从复制架构及实现

实战:主主复制

[[email protected] ~]# systemctl stop mariadb.service 

[[email protected] ~]# systemctl stop mariadb.service

[[email protected] ~]# rm -rf /var/lib/mysql/*

[[email protected] ~]# rm -rf /var/lib/mysql/*

[[email protected] ~]# vim /etc/my.cnf

添加

log-bin=master-bin

relay_log=relay-log

server-id=1

innodb_file_per_table=ON

skip_name_resolve=ON

auto_increment_offset=1

auto_increment_increment=2

[[email protected] ~]# vim /etc/my.cnf

添加

log-bin=master-bin

relay_log=relay-log

server-id=5

innodb_file_per_table=ON

skip_name_resolve=ON

auto_increment_offset=2

auto_increment_increment=2

[[email protected] ~]# systemctl start mariadb.service 

[[email protected] ~]# mysql

#确保relay_log值为relay-log

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘relay_log‘;

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

| Variable_name | Value     |

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

| relay_log     | relay-log |

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

#确保log_bin值为ON

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘log_bin‘;

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

| Variable_name | Value |

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

| log_bin       | ON    |

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

[[email protected] ~]# systemctl start mariadb.service 

[[email protected] ~]# mysql

#确保relay_log值为relay-log

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘relay_log‘;

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

| Variable_name | Value     |

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

| relay_log     | relay-log |

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

#确保log_bin值为ON

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘log_bin‘;

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

| Variable_name | Value |

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

| log_bin       | ON    |

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

#主节点

MariaDB [(none)]> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repluser‘@‘192.168.%.%‘ IDENTIFIED BY ‘replpass‘;

MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> SHOW MASTER STATUS;

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

| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| master-bin.000003 |      507 |              |                  |

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

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘192.168.1.132‘,MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,MASTER_LOG_POS=507;

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: 

 Master_Host: 192.168.1.132

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 507

  Relay_Log_File: relay-log.000001

Relay_Log_Pos: 4

Relay_Master_Log_File: master-bin.000003

MariaDB [(none)]> START SLAVE;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.132

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 507

  Relay_Log_File: relay-log.000002

Relay_Log_Pos: 530

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

#从节点

MariaDB [(none)]> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repluser‘@‘192.168.%.%‘ IDENTIFIED BY ‘replpass‘;

MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> SHOW MASTER STATUS;

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

| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| master-bin.000003 |      507 |              |                  |

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

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘192.168.1.131‘,MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,MASTER_LOG_POS=507;

MariaDB [(none)]> SHOW SLAVE STATUS \G                               _USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,

*************************** 1. row ***************************

  Slave_IO_State: 

 Master_Host: 192.168.1.131

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 507

  Relay_Log_File: relay-log.000001

Relay_Log_Pos: 4

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: No

Slave_SQL_Running: No

MariaDB [(none)]> START SLAVE;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.131

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 507

  Relay_Log_File: relay-log.000002

Relay_Log_Pos: 530

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

测试1:主结点创建一个数据库mydb

#主节点

MariaDB [(none)]> CREATE DATABASE mydb;

MariaDB [(none)]> SHOW SLAVE STATUS \G 

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.132

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 507

  Relay_Log_File: relay-log.000002

Relay_Log_Pos: 530

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

#从结点:

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.131

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 595

  Relay_Log_File: relay-log.000002

Relay_Log_Pos: 618

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

MariaDB [(none)]> SHOW DATABASES;

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

| Database           |

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

| information_schema |

| mydb               |

| mysql              |

| performance_schema |

| test               |

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

结果:从节点已复制主节点的数据库

测试2:从结点在主节点创建的数据库mydb中创建数据表tb1

#从结点:

MariaDB [(none)]> USE mydb;

Database changed

MariaDB [mydb]> CREATE TABLE tb1 (id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,name CHAR(30));

MariaDB [mydb]> DESC tb1;

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

| Field | Type             | Null | Key | Default | Extra          |

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

| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |

| name  | char(30)         | YES  |     | NULL    |                |

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

MariaDB [mydb]> SHOW MASTER STATUS;

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

| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| master-bin.000003 |      659 |              |                  |

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

#主结点

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.132

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 659

  Relay_Log_File: relay-log.000002

Relay_Log_Pos: 682

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

MariaDB [(none)]> use mydb;

MariaDB [mydb]> SHOW TABLES;

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

| Tables_in_mydb |

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

| tb1            |

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

1 row in set (0.00 sec)

MariaDB [mydb]> DESC tb1;

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

| Field | Type             | Null | Key | Default | Extra          |

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

| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |

| name  | char(30)         | YES  |     | NULL    |                |

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

MariaDB [mydb]> INSERT INTO tb1 (name) VALUES(‘Yang Kang‘),(‘Yang Guo‘),(‘Yang Yanzhao‘);MariaDB [mydb]> SELECT * FROM tb1;

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

| id | name         |

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

|  1 | Yang Kang    |

|  3 | Yang Guo     |

|  5 | Yang Yanzhao |

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

#从结点

MariaDB [mydb]> SELECT * FROM tb1;

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

| id | name         |

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

|  1 | Yang Kang    |

|  3 | Yang Guo     |

|  5 | Yang Yanzhao |

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

MariaDB [mydb]> INSERT INTO tb1 (name) VALUES(‘Zhu Yuanzhang‘),(‘Zhu Di‘),(‘Zhu Yue‘);

MariaDB [mydb]>  SELECT * FROM tb1;

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

| id | name          |

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

|  1 | Yang Kang     |

|  3 | Yang Guo      |

|  5 | Yang Yanzhao  |

|  6 | Zhu Yuanzhang |

|  8 | Zhu Di        |

| 10 | Zhu Yue       |

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

#主节点

MariaDB [mydb]> SELECT * FROM tb1;

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

| id | name          |

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

|  1 | Yang Kang     |

|  3 | Yang Guo      |

|  5 | Yang Yanzhao  |

|  6 | Zhu Yuanzhang |

|  8 | Zhu Di        |

| 10 | Zhu Yue       |

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

MariaDB [mydb]> INSERT INTO tb1 (name) VALUES(‘Mao Ze‘);

Query OK, 1 row affected (0.02 sec)

MariaDB [mydb]> SELECT * FROM tb1;                      

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

| id | name          |

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

|  1 | Yang Kang     |

|  3 | Yang Guo      |

|  5 | Yang Yanzhao  |

|  6 | Zhu Yuanzhang |

|  8 | Zhu Di        |

| 10 | Zhu Yue       |

| 11 | Mao Ze        |

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

测试结果:主节点从从结点同步数据成功

实战:半同步复制

[[email protected] ~]# systemctl stop mariadb.service 

[[email protected] ~]# systemctl stop mariadb.service

[[email protected] ~]# rm -rf /var/lib/mysql/*

[[email protected] ~]# rm -rf /var/lib/mysql/*

[[email protected] ~]# vim /etc/my.cnf

添加

log-bin=master-bin

server-id=1

innodb_file_per_table=ON

skip_name_resolve=ON

[[email protected] ~]# vim /etc/my.cnf

添加

relay_log=relay-log

server-id=5

innodb_file_per_table=ON

skip_name_resolve=ON

[[email protected] ~]# systemctl start mariadb.service

[[email protected] ~]# systemctl start mariadb.service 

#主服务器

[[email protected] ~]# mysql

MariaDB [(none)]> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repluser‘@‘192.168.%.%‘ IDENTIFIED BY ‘replpass‘;

MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> SHOW MASTER STATUS;

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

| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| master-bin.000003 |      497 |              |                  |

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

#从服务器

[[email protected] ~]# mysql

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST=‘192.168.1.131‘,MASTER_USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,MASTER_LOG_POS=497;

MariaDB [(none)]> START SLAVE;                                       _USER=‘repluser‘,MASTER_PASSWORD=‘replpass‘,MASTER_LOG_FILE=‘master-bin.000003‘,

Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.131

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 497

  Relay_Log_File: relay-log.000002

Relay_Log_Pos: 530

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

MariaDB [(none)]> STOP SLAVE;

#主节点

MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME ‘semisync_master.so‘;

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘%semi%‘;

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

| Variable_name                      | Value |

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

| rpl_semi_sync_master_enabled       | OFF   |

| rpl_semi_sync_master_timeout       | 10000 |

| rpl_semi_sync_master_trace_level   | 32    |

| rpl_semi_sync_master_wait_no_slave | ON    |

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

MariaDB [(none)]> SHOW GLOBAL STATUS LIKE ‘%semi%‘;

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

| Variable_name                              | Value |

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

| Rpl_semi_sync_master_clients               | 0     |

| Rpl_semi_sync_master_net_avg_wait_time     | 0     |

| Rpl_semi_sync_master_net_wait_time         | 0     |

| Rpl_semi_sync_master_net_waits             | 0     |

| Rpl_semi_sync_master_no_times              | 0     |

| Rpl_semi_sync_master_no_tx                 | 0     |

| Rpl_semi_sync_master_status                | OFF   |

| Rpl_semi_sync_master_timefunc_failures     | 0     |

| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |

| Rpl_semi_sync_master_tx_wait_time          | 0     |

| Rpl_semi_sync_master_tx_waits              | 0     |

| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |

| Rpl_semi_sync_master_wait_sessions         | 0     |

| Rpl_semi_sync_master_yes_tx                | 0     |

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

MariaDB [(none)]> SET GLOBAL rpl_semi_sync_master_enabled=1;

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘%semi%‘;         

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

| Variable_name                      | Value |

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

| rpl_semi_sync_master_enabled       | ON    |

| rpl_semi_sync_master_timeout       | 10000 |

| rpl_semi_sync_master_trace_level   | 32    |

| rpl_semi_sync_master_wait_no_slave | ON    |

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

#从结点

MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME ‘semisync_slave.so‘;

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘%semi%‘;

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

| Variable_name                      | Value |

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

| rpl_semi_sync_slave_enabled        | OFF   |

| rpl_semi_sync_slave_trace_level    | 32    |

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

MariaDB [(none)]> SET GLOBAL rpl_semi_sync_slave_enabled=1;

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘%semi%‘;     

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

| Variable_name                      | Value |

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

| rpl_semi_sync_slave_enabled        | ON    |

| rpl_semi_sync_slave_trace_level    | 32    |

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

MariaDB [(none)]> START SLAVE;

Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.131

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 497

  Relay_Log_File: relay-log.000003

Relay_Log_Pos: 530

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

#主服务器

MariaDB [(none)]> SHOW GLOBAL STATUS LIKE ‘%semi%‘;         

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

| Variable_name                              | Value |

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

| Rpl_semi_sync_master_clients               | 1     |

| Rpl_semi_sync_master_net_avg_wait_time     | 0     |

| Rpl_semi_sync_master_net_wait_time         | 0     |

| Rpl_semi_sync_master_net_waits             | 0     |

| Rpl_semi_sync_master_no_times              | 0     |

| Rpl_semi_sync_master_no_tx                 | 0     |

| Rpl_semi_sync_master_status                | ON    |

| Rpl_semi_sync_master_timefunc_failures     | 0     |

| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |

| Rpl_semi_sync_master_tx_wait_time          | 0     |

| Rpl_semi_sync_master_tx_waits              | 0     |

| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |

| Rpl_semi_sync_master_wait_sessions         | 0     |

| Rpl_semi_sync_master_yes_tx                | 0     |

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

MariaDB [(none)]> CREATE DATABASE mydb;

Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> USE mydb;

MariaDB [mydb]> CREATE TABLE tb1 (id int,name char(30));

MariaDB [mydb]> SHOW GLOBAL STATUS LIKE ‘%semi%‘;

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

| Variable_name                              | Value |

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

| Rpl_semi_sync_master_clients               | 1     |

| Rpl_semi_sync_master_net_avg_wait_time     | 1759  |

| Rpl_semi_sync_master_net_wait_time         | 3518  |

| Rpl_semi_sync_master_net_waits             | 2     |

| Rpl_semi_sync_master_no_times              | 0     |

| Rpl_semi_sync_master_no_tx                 | 0     |

| Rpl_semi_sync_master_status                | ON    |

| Rpl_semi_sync_master_timefunc_failures     | 0     |

| Rpl_semi_sync_master_tx_avg_wait_time      | 2437  |

| Rpl_semi_sync_master_tx_wait_time          | 4875  |

| Rpl_semi_sync_master_tx_waits              | 2     |

| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |

| Rpl_semi_sync_master_wait_sessions         | 0     |

| Rpl_semi_sync_master_yes_tx                | 2     |

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

实战:复制过滤器

#从服务器

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘replicate%‘;

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

| Variable_name                    | Value     |

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

| replicate_annotate_row_events    | OFF       |

| replicate_do_db                  |           |

| replicate_do_table               |           |

| replicate_events_marked_for_skip | replicate |

| replicate_ignore_db              |           |

| replicate_ignore_table           |           |

| replicate_wild_do_table          |           |

| replicate_wild_ignore_table      |           |

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

MariaDB [(none)]> STOP SLAVE;

MariaDB [(none)]> SET GLOBAL replicate_do_db=mydb;  

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE ‘replicate%‘;

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

| Variable_name                    | Value     |

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

| replicate_annotate_row_events    | OFF       |

| replicate_do_db                  | mydb      |

| replicate_do_table               |           |

| replicate_events_marked_for_skip | replicate |

| replicate_ignore_db              |           |

| replicate_ignore_table           |           |

| replicate_wild_do_table          |           |

| replicate_wild_ignore_table      |           |

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

MariaDB [(none)]> START SLAVE;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW SLAVE STATUS \G

*************************** 1. row ***************************

  Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.1.131

 Master_User: repluser

 Master_Port: 3306

Connect_Retry: 60

 Master_Log_File: master-bin.000003

 Read_Master_Log_Pos: 682

  Relay_Log_File: relay-log.000004

Relay_Log_Pos: 530

Relay_Master_Log_File: master-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

 Replicate_Do_DB: mydb

#主服务器

MariaDB [mydb]> CREATE DAMariaDB [mydb]> SHOW DATABASES;

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

| Database           |

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

| information_schema |

| mydb               |

| mysql              |

| performance_schema |

| test               |

| testdb             |

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

#从服务器

MariaDB [(none)]> SHOW DATABASES;

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

| Database           |

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

| information_schema |

| mydb               |

| mysql              |

| performance_schema |

| test               |

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

#主服务器

MariaDB [mydb]> INSERT INTO tb1 VALUES (1,"a");

#从服务器

MariaDB [(none)]> USE mydb;

MariaDB [mydb]> SELECT * FROM tb1;

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

| id   | name |

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

|    1 | a    |

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

实战:清理mysql日志

MariaDB [mydb]> SHOW BINARY LOGS;

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

| Log_name          | File_size |

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

| master-bin.000001 |     30334 |

| master-bin.000002 |   1038814 |

| master-bin.000003 |       957 |

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

MariaDB [mydb]> PURGE BINARY LOGS TO ‘master-bin.000002‘;

MariaDB [mydb]> SHOW BINARY LOGS;                        

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

| Log_name          | File_size |

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

| master-bin.000002 |   1038814 |

| master-bin.000003 |       957 |

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

MariaDB [mydb]> PURGE BINARY LOGS TO ‘master-bin.000003‘;

Query OK, 0 rows affected (0.02 sec)

MariaDB [mydb]> SHOW BINARY LOGS;                        

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

| Log_name          | File_size |

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

| master-bin.000003 |       957 |

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

[[email protected] ~]# ls /var/lib/mysql/

aria_log.00000001  ib_logfile1        mysql               testdb

aria_log_control   master-bin.000003  mysql.sock

ibdata1            master-bin.index   performance_schema

ib_logfile0        mydb               test

注意:日志清理后,其对应的文件也会被删除

时间: 2024-10-09 22:08:51

42-4 mysql主从复制的相关文章

mysql主从复制与读写分离

MySQL主从复制与读写分离 MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中,由单台Mysql作为独立的数据库是完全不能满足实际需求的,无论是在安全性,高可用性以及高并发等各个方面. 因此,一般来说都是通过 主从复制(Master-Slave)的方式来同步数据,再通过读写分离(MySQL-Proxy)来提升数据库的并发负载能力 这样的方案来进行部

基于SSL的Mysql主从复制

一.实验目的: 1.跨越互联网加密复制 mysql基于SSL加密连接,为安全从服配置证书,从服拿账号到主服复制时,必须得到主服验证.双方建立SSL会话. 二.实验架构 在分布式架构中,时间必须同步 主节点: station20:192.168.1.20 从节点: station21:192.168.1.21 三.实验步骤 1.建立ssh互信 [[email protected] ~]# echo -e"192.168.1.21\tstation21\tstation21.example.com&

MySQL主从复制与读写分离的实现

MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中,由单台Mysql作为独立的数据库是完全不能满足实际需求的,无论是在安全性,高可用性以及高并发等各个方面. 因此,一般来说都是通过 主从复制(Master-Slave)的方式来同步数据,再通过读写分离(MySQL-Proxy)来提升数据库的并发负载能力 这样的方案来进行部署与实施的. 如下图所示: 下

MySQL主从复制与读写分离 --非原创

原文出处:http://www.cnblogs.com/luckcs/articles/2543607.html MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中,由单台Mysql作为独立的数据库是完全不能满足实际需求的,无论是在安全性,高可用性以及高并发等各个方面. 因此,一般来说都是通过 主从复制(Master-Slave)的方式来同步数据,再

MySQL 主从复制 + MySQL Router 部署测试

4个节点 1.MySQLDB1  192.168.1.41  (MySQL 主节点) 2.MySQLDB2  192.168.1.42  (MySQL从节点) 3.MySQLDB3  192.168.1.43  (MySQL从节点) 4.MySQLRouter  192.168.1.47  (MySQLRouter服务节点) 软件版本说明: 1.操作系统  CentOS6.6_x86_64 2.MySQLServer  5.7.16 3.MySQLRouter  2.0.4 一.部署MySQL主

MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践

Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中,由单台Mysql作为独立的数据库是完全不能满足实际需求的,无论是在安全性,高可用性以及高并发等各个方面. 因此,一般来说都是通过 主从复制(Master-Slave)的方式来同步数据,再通过读写分离(MySQL-Proxy)来提升数据库的并发负载能力 这样的方案来进行部署与实施的. 如下图所示: 下面是我在实际工作过程中所整理的笔记,在此分享出来,以供大家参考. 一.MySQL的安装与

mysql主从复制实现(基于mysql5.5版本)

一,mysql主从复制原理介绍: mysql的复制是基于二进制日志实现的,二进制日志记录的是一切可能引起数据库发生改变的操作,因此,二进制日志对mysql十分重要,利用它可以实现数据库的即时点还原,对于备份恢复数据库意义重大. mysql复制中,主服务器的事务操作提交后,会将事件记录到二进制日中去,这时从服务器会启动IO_Thread来与主服务器通信,将主服务器中的二进制日志中的事件复制到本地并保存在本地的中继日志中,而后,从服务器会通过SQL_Thread将中继日志中的事件提取出来在数据库中进

Linux下Mysql主从复制

一.前言:为什么MySQL要做主从复制(读写分离)?通俗来讲,如果对数据库的读和写都在同一个数据库服务器中操作,业务系统性能会降低.为了提升业务系统性能,优化用户体验,可以通过做主从复制(读写分离)来减轻主数据库的负载.而且如果主数据库宕机,可快速将业务系统切换到从数据库上,可避免数据丢失. 二.MySQL主从复制(读写分离)和集群的区别:我对MySQL也是刚开始研究,不是很专业.我的理解是:1.主从复制(读写分离):一般需要两台及以上数据库服务器即可(一台用于写入数据,一台用于同步主的数据并用

mysql主从复制的一篇文章(转载)

管理mysql主从有2年多了,管理过200多组mysql主从,几乎涉及到各个版本的主从,本博文属于总结性的,有一部分是摘自网络,大部分是根据自己管理的心得和经验所写,整理了一下,分享给各位同行,希望对大家有帮助,互相交流. 一.mysql主从的原理 1.Replication 线程 Mysql的 Replication 是一个异步的复制过程(mysql5.1.7以上版本分为异步复制和半同步两种模式),从一个 Mysql instace(我们称之为 Master)复制到另一个 Mysql inst

linux Mysql 主从复制 原理介绍和步骤详解

大家好,我是霸王卸甲,今天我给大家带来的是linux数据库中的主从复制的简单介绍和步骤详解. 主从复制 mysql主从复制 灵活 一主一从 主主复制 一主多从---扩展系统读取的性能,因为读是在从库读取的: 多主一从---5.7开始支持 联级复制--- 用途及条件 mysql主从复制用途 实时灾备,用于故障切换 读写分离,提供查询服务 备份,避免影响业务 主从部署必要条件: 主库开启binlog日志(设置log-bin参数) 主从server-id不同 从库服务器能连通主库 主从原理mysql主