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 root@10.10.54.64 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

相關文章
相關標籤/搜索