MySQL树形复制—BLACKHOLE存储引擎的使用

实现如下架构

54.64(master)---54.67(blackhole)----54.63(innodb)

mysql5.5复制配置

1.规划网络和主从机器
master:10.10.54.64
blackhole slave:10.10.54.67
slave:10.10.54.63
2.master config

log-bin=master-bin
server-id=1
binlog_formate=mixed

[root@gyf  ~]# /etc/init.d/mysqld restart

3.

blackhole slave config10.10.54.67
[root@gyf  ~]# vim /etc/my.cnf
default_storage_engine = blackhole
log-slave-update = 1
log-bin=blackhole-bin
binlog_formate=mixed
skip-innodb
server-id=10必须大于主
[root@gyf  ~]# /etc/init.d/mysqld restart

slave config10.10.54.63
log-bin=slave-bin
binlog_formate=mixed
server-id=11必须大于主
[root@gyf  ~]# /etc/init.d/mysqld restart

4.在master上面创建一个复制用户并授予权限
mysql> grant replication slave on *.* to 'gyf'@'10.10.54.67' identified by 'aaa12345';
mysql> flush privileges;
在blavehole slave 创建一个复制用户
mysql> grant replication slave on *.* to 'gyf'@'10.10.54.63' identified by 'aaa12345';
mysql> flush privileges;
//在blavehole slave上测试是否能用复制用户登录
[root@gyf  ~]# mysql -ugyf -paaa12345 -h10.10.54.64
//在slave上测试是否能用复制用户登录blavehole slave
[root@gyf  ~]# mysql -ugyf -paaa12345 -h10.10.54.67
5.查看master上二进制日志和position位置
root@(none) 18:14>show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000008 |      942 |              |                  |
+-------------------+----------+--------------+------------------+
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=751;
//查看blavehole slave上二进制日志和position位置
root@(none) 19:58>show master status;
+----------------------+----------+--------------+------------------+
| File                 | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------------+----------+--------------+------------------+
| blackhole-bin.000002 |     1323 |              |                  |
+----------------------+----------+--------------+------------------+
拓展:重置master  reset master
6.备份master上的数据,把备份maste数据库还原到从库上
[root@gyf  ~]# mysqldump -uroot -paaa12345 --databases employees |mysql -uroot -paaa12345 -h10.10.54.67
[root@gyf  ~]# mysqldump -uroot -paaa12345 --databases master |mysql -uroot -paaa12345 -h10.10.54.67
或者////
[root@nan86 tmp]# mysqldump -uroot -paaa12345 --master-data=2 --single-transaction --flush-logs --database employees >employees.sql

[root@gyf  ~]# mysqldump -uroot -paaa12345 --databases employees |mysql -uroot -paaa12345 -h10.10.54.67

[root@gyf  tmp]# mysql -uroot -paaa12345 -h10.10.54.67<employees.sql
ERROR 1130 (HY000): Host '10.10.54.64' is not allowed to connect to this MySQL server

mysql> grant all privileges on *.*  to [email protected] identified by 'aaa12345';
mysql> flush privileges;

[root@nan86 tmp]# mysql -uroot -paaa12345 -h10.10.54.67<employees.sql

7.
在blackhole slave上面change master操作10.10.54.67
root@(none) 20:08>change master to master_host='10.10.54.64',master_user='gyf',master_password='aaa12345',master_log_file='master-bin.000008',master_log_pos=942;


在slave上面change master操作10.10.54.63
root@(none) 20:10>change master to master_host='10.10.54.67',master_user='gyf',master_password='aaa12345',master_log_file='master-bin.000002',master_log_pos=1323;

8.在slave上启动slave
mysql> start slave;   
9.
查看blackhole slave的状态
root@(none) 20:12>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.54.64
                  Master_User: gyf
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000008
          Read_Master_Log_Pos: 942
               Relay_Log_File: Cent67-relay-bin.000002
                Relay_Log_Pos: 254
        Relay_Master_Log_File: master-bin.000008
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

//查看slave状态
确定slave上的I/O线程和SQL线程状态为YES
root@(none) 20:17>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 10.10.54.67
                  Master_User: gyf
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: blackhole-bin.000001
          Read_Master_Log_Pos: 107
               Relay_Log_File: gyf-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: blackhole-bin.000001
                               
                Last_IO_Errno: 1236
                Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
解决方法:
在slave
 stop slave;
在blackhole  
flush logs;
show master status;
在slave
change master


//可以单独停掉某一个线程
mysql> STOP SLAVE IO_THREAD;
mysql> STOP SLAVE SQL_THREAD;





###测试
在master上
root@(none) 19:19>use test;

root@test  19:22>create table aa(a int);
root@test  19:24>insert into aa values (1),(2),(3);

root@test  19:24>select * from aa;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
+------+

root@(none) 18:43>drop database a;
root@(none) 18:43>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| employees          |
| mysql              |
| performance_schema |
| test               |
+--------------------+

在blackhole slave上显示
root@(none) 21:04>use test;
Database changed
root@test  21:05>show tables;
+----------------+
| Tables_in_test |
+----------------+
| aa             |
+----------------+
root@test  21:05>select * from aa;
Empty set (0.00 sec)
root@test  21:18>show create table aa;
CREATE TABLE `aa` (
  `a` int(11) DEFAULT NULL
) ENGINE=BLACKHOLE DEFAULT CHARSET=utf8
在 slave上显示
root@(none) 21:04>use test;
Database changed
root@test  21:05>show tables;
+----------------+
| Tables_in_test |
+----------------+
| aa             |
+----------------+

root@test  21:05>select * from aa;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
+------+


你可能感兴趣的:(MySQL树形复制—BLACKHOLE存储引擎的使用)