麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 課堂 > 基礎知識 > 正文

Mariadb多主一從的創建

2024-09-12 20:30:01
字體:
來源:轉載
供稿:網友
      目前MySQL依然只支持一個Slave從一個Master復制數據,雖然也可以做到一主多備(M->S),雙主復制(M<->M)等架構,但是局限性依然很大。由于項目的要求,需要各個主庫的表整合到一個地方進行統計和分析,要是每次連不同的實例操作,是一件非常耗體力的操作。所以繼續一種類似多主一從的實例。
 
        安裝:
 
sudo apt-get install software-properties-common
 
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
 
sudo add-apt-repository 'deb http://mirrors.hustunique.com/mariadb/repo/10.0/ubuntu trusty main'
 
sudo apt-get update
 
sudo apt-get install mariadb-server
 
       環境搭建:
 
Master 1:200.51(MySQL)
 
Master 2:200.52(MySQL)
 
Slave   :200.73(MariaDB) 修改好server-id
 
         確認好Master的POS:
 
M1:
 
[email protected] : (none) 10:26:11>show master status;
 
+--------------------+----------+--------------+------------------+
 
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 
+--------------------+----------+--------------+------------------+
 
| mysql-bin51.000013 |      107 |              | test             |
 
+--------------------+----------+--------------+------------------+
 
1 row in set (0.01 sec)
 
M2:
 
[email protected] : r2 10:26:23>show master status;                                                                                   +---------------------+----------+--------------+------------------+
 
| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 
+---------------------+----------+--------------+------------------+
 
| mysql-bin_52.000106 |      107 |              | test             |
 
+---------------------+----------+--------------+------------------+
 
1 row in set (0.00 sec)
 
Slave 操作:
 
MariaDB [(none)]> change master 'r1' to master_host='192.168.200.51',master_user='rep',master_password='rep123456',master_log_file='mysql-bin51.000013',master_log_pos=107;
 
Query OK, 0 rows affected (0.23 sec)
 
MariaDB [(none)]> change master 'r2' to master_host='192.168.200.52',master_user='rep',master_password='rep123456',master_log_file='mysql-bin_52.000106',master_log_pos=107;
 
Query OK, 0 rows affected (0.25 sec)
 
MariaDB的change方法和MySQL有點不一樣,多了一個 ['connection_name'] ,這個就是多主一從的關鍵。為每個主設置一個通道標識,這樣就可以支持多主復制了。
 
如何保存復制的信息?單主復制會把復制信息保存在master.info中,在多主復制中的保存也類似,只是在最后加上通道標識名稱。如:
 
-rw-rw---- 1 mysql mysql  113 11月 17 10:30 master-r1.info
 
-rw-rw---- 1 mysql mysql  114 11月 17 10:31 master-r2.info
 
-rw-rw---- 1 mysql mysql  248 11月 17 10:30 mysqld-relay-bin-r1.000001
 
-rw-rw---- 1 mysql mysql   29 11月 17 10:30 mysqld-relay-bin-r1.index
 
-rw-rw---- 1 mysql mysql  248 11月 17 10:31 mysqld-relay-bin-r2.000001
 
-rw-rw---- 1 mysql mysql   29 11月 17 10:31 mysqld-relay-bin-r2.index
 
-rw-rw---- 1 mysql mysql   54 11月 17 10:30 relay-log-r1.info
 
-rw-rw---- 1 mysql mysql   55 11月 17 10:31 relay-log-r2.info
 
查看同步:
 
#查看所有通道
MariaDB [(none)]> show all slaves status/G;
 
*************************** 1. row ***************************
 
              Connection_name: r1
 
              Slave_SQL_State:
 
               Slave_IO_State:
 
                  Master_Host: 192.168.200.51
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin51.000013
 
          Read_Master_Log_Pos: 107
 
               Relay_Log_File: mysqld-relay-bin-r1.000001
 
                Relay_Log_Pos: 4
 
        Relay_Master_Log_File: mysql-bin51.000013
 
             Slave_IO_Running: No
 
            Slave_SQL_Running: No
 
              Replicate_Do_DB:
 
          Replicate_Ignore_DB:
 
           Replicate_Do_Table:
 
       Replicate_Ignore_Table:
 
      Replicate_Wild_Do_Table:
 
  Replicate_Wild_Ignore_Table:
 
                   Last_Errno: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 107
 
              Relay_Log_Space: 248
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: NULL
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 0
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
         Retried_transactions: 0
 
           Max_relay_log_size: 104857600
 
         Executed_log_entries: 0
 
    Slave_received_heartbeats: 0
 
       Slave_heartbeat_period: 1800.000
 
               Gtid_Slave_Pos:
 
*************************** 2. row ***************************
 
              Connection_name: r2
 
              Slave_SQL_State:
 
               Slave_IO_State:
 
                  Master_Host: 192.168.200.52
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin_52.000106
 
          Read_Master_Log_Pos: 107
 
               Relay_Log_File: mysqld-relay-bin-r2.000001
 
                Relay_Log_Pos: 4
 
        Relay_Master_Log_File: mysql-bin_52.000106
 
             Slave_IO_Running: No
 
            Slave_SQL_Running: No
 
              Replicate_Do_DB:
 
          Replicate_Ignore_DB:
 
           Replicate_Do_Table:
 
       Replicate_Ignore_Table:
 
      Replicate_Wild_Do_Table:
 
  Replicate_Wild_Ignore_Table:
 
                   Last_Errno: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 107
 
              Relay_Log_Space: 248
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: NULL
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 0
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
         Retried_transactions: 0
 
           Max_relay_log_size: 104857600
 
         Executed_log_entries: 0
 
    Slave_received_heartbeats: 0
 
       Slave_heartbeat_period: 1800.000
 
               Gtid_Slave_Pos:
 
2 rows in set (0.00 sec)
 
ERROR: No query specified
 
 
#查看單個通道
 
MariaDB [(none)]> show slave 'r1' status/G;
 
*************************** 1. row ***************************
 
               Slave_IO_State:
 
                  Master_Host: 192.168.200.51
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin51.000013
 
          Read_Master_Log_Pos: 107
 
               Relay_Log_File: mysqld-relay-bin-r1.000001
 
                Relay_Log_Pos: 4
 
        Relay_Master_Log_File: mysql-bin51.000013
 
             Slave_IO_Running: No
 
            Slave_SQL_Running: No
 
              Replicate_Do_DB:
 
          Replicate_Ignore_DB:
 
           Replicate_Do_Table:
 
       Replicate_Ignore_Table:
 
      Replicate_Wild_Do_Table:
 
  Replicate_Wild_Ignore_Table:
 
                   Last_Errno: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 107
 
              Relay_Log_Space: 248
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: NULL
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 0
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
1 row in set (0.00 sec)
 
ERROR: No query specified
 
MariaDB [(none)]> show slave 'r2' status/G;
 
*************************** 1. row ***************************
 
               Slave_IO_State:
 
                  Master_Host: 192.168.200.52
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin_52.000106
 
          Read_Master_Log_Pos: 107
 
               Relay_Log_File: mysqld-relay-bin-r2.000001
 
                Relay_Log_Pos: 4
 
        Relay_Master_Log_File: mysql-bin_52.000106
 
             Slave_IO_Running: No
 
            Slave_SQL_Running: No
 
              Replicate_Do_DB:
 
          Replicate_Ignore_DB:
 
           Replicate_Do_Table:
 
       Replicate_Ignore_Table:
 
      Replicate_Wild_Do_Table:
 
  Replicate_Wild_Ignore_Table:
 
                   Last_Errno: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 107
 
              Relay_Log_Space: 248
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: NULL
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 0
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
1 row in set (0.00 sec)
 
ERROR: No query specified
 
開啟同步:
 
#開啟單個通道
MariaDB [(none)]> start slave 'r1';
 
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [(none)]> start slave 'r2';
 
Query OK, 0 rows affected (0.00 sec)
 
#關閉多個通道
 
MariaDB [(none)]> start all slaves;
 
Query OK, 0 rows affected, 2 warnings (0.01 sec)
 
MariaDB [(none)]> show warnings;
 
+-------+------+--------------------+
 
| Level | Code | Message            |
 
+-------+------+--------------------+
 
| Note  | 1937 | SLAVE 'r2' started |
 
| Note  | 1937 | SLAVE 'r1' started |
 
+-------+------+--------------------+
 
2 rows in set (0.00 sec)
 
通過 show all slaves status 命令可知是否同步成功。
 
關閉同步:
 
#關閉單個通道
MariaDB [(none)]> stop slave 'r1';
 
Query OK, 0 rows affected (0.14 sec)
 
MariaDB [(none)]> stop slave 'r2';
 
Query OK, 0 rows affected (0.03 sec)
 
#關閉所有通道
 
MariaDB [(none)]> stop all slaves;
 
Query OK, 0 rows affected, 2 warnings (0.08 sec)
 
MariaDB [(none)]> show warnings;
 
+-------+------+--------------------+
 
| Level | Code | Message            |
 
+-------+------+--------------------+
 
| Note  | 1938 | SLAVE 'r2' stopped |
 
| Note  | 1938 | SLAVE 'r1' stopped |
 
+-------+------+--------------------+
 
2 rows in set (0.00 sec)
 
多源復制在原先復制的基礎上多了幾個變量,現在來說明下:
 
MariaDB [(none)]> show all slaves status/G;
 
*************************** 1. row ***************************
 
              Connection_name: r1                #master的連接名,通道名,第一個參數。
 
              Slave_SQL_State: Slave has read all relay log; waiting for the slave I/O thread to update it
 
               Slave_IO_State: Waiting for master to send event
 
                  Master_Host: 192.168.200.51
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin51.000013
 
          Read_Master_Log_Pos: 107
 
               Relay_Log_File: mysqld-relay-bin-r1.000005
 
                Relay_Log_Pos: 396
 
        Relay_Master_Log_File: mysql-bin51.000013
 
             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: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 107
 
              Relay_Log_Space: 845
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: 0
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 1
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
         Retried_transactions: 0          #這個連接重試事務的次數
 
           Max_relay_log_size: 104857600  #relay log的最大值. 如果是0的話,那么在啟動的時候就會被設置成max_binlog_size 的大小
 
         Executed_log_entries: 17         #slave已經指向了多少個日志條目
 
    Slave_received_heartbeats: 0          #我們從master收到了多少個心跳包
 
       Slave_heartbeat_period: 1800.000   #多久從master請求一個心跳包 (以秒計算)
 
               Gtid_Slave_Pos:
 
 測試復制
 
Master 1:
 
[email protected] : (none) 01:52:34>show databases;
 
+--------------------+
 
| Database           |
 
+--------------------+
 
| information_schema |
 
| mha_test           |
 
| mysql              |
 
| performance_schema |
 
| xtra_test          |
 
+--------------------+
 
5 rows in set (0.00 sec)
 
[email protected] : (none) 01:52:37>create database r1 default charset utf8;
 
Query OK, 1 row affected (0.01 sec)
 
[email protected] : (none) 01:53:36>use r1;
 
Database changed
 
[email protected] : r1 01:53:44>create table r1(id int not null auto_increment primary key,name varchar(30))default charset utf8;
 
Query OK, 0 rows affected (1.35 sec)
 
[email protected] : r1 01:54:09>insert into r1(name) values('a'),('b'),('c');
 
Query OK, 3 rows affected (0.01 sec)
 
Records: 3  Duplicates: 0  Warnings: 0
 
[email protected] : r1 01:54:56>select * from r1;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | a    |
 
|  2 | b    |
 
|  3 | c    |
 
+----+------+
 
3 rows in set (0.00 sec)
 
Master 2:
 
[email protected] : (none) 01:52:13>create database r2 default charset utf8;
 
Query OK, 1 row affected (0.01 sec)
 
[email protected] : (none) 01:54:27>use r2
 
Database changed
 
[email protected] : r2 01:54:30>create table r2(id int not null auto_increment primary key,name varchar(30))default charset utf8;
 
Query OK, 0 rows affected (0.23 sec)
 
[email protected] : r2 01:54:32>insert into r2(name) values('A'),('B'),('C');
 
Query OK, 3 rows affected (0.28 sec)
 
Records: 3  Duplicates: 0  Warnings: 0
 
[email protected] : r2 01:55:18>select * from r2;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | A    |
 
|  2 | B    |
 
|  3 | C    |
 
+----+------+
 
3 rows in set (0.01 sec)
 
Slave:
 
MariaDB [(none)]> show databases;
 
+--------------------+
 
| Database           |
 
+--------------------+
 
| information_schema |
 
| mysql              |
 
| performance_schema |
 
| r1                 |
 
| r2                 |
 
+--------------------+
 
5 rows in set (0.00 sec)
 
MariaDB [(none)]> use r1;
 
Reading table information for completion of table and column names
 
You can turn off this feature to get a quicker startup with -A
 
Database changed
 
MariaDB [r1]> select * from r1;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | a    |
 
|  2 | b    |
 
|  3 | c    |
 
+----+------+
 
3 rows in set (0.00 sec)
 
MariaDB [r1]> use r2;
 
Reading table information for completion of table and column names
 
You can turn off this feature to get a quicker startup with -A
 
Database changed
 
MariaDB [r2]> select * from r2;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | A    |
 
|  2 | B    |
 
|  3 | C    |
 
+----+------+
 
3 rows in set (0.00 sec)
 
同步成功,那如何錯誤跳過呢(default_master_connection)?
 
在Master 1上創建r2數據庫,因為Slave上存在,所以會報錯:
 
Master 1:
 
[email protected] : r1 01:55:52>create database r2 default charset utf8;
 
Query OK, 1 row affected (0.01 sec)
 
[email protected] : r1 01:59:51>insert into r1(name) values('d'),('e'),('f');
 
Query OK, 3 rows affected (0.01 sec)
 
Records: 3  Duplicates: 0  Warnings: 0
 
[email protected] : r1 02:04:22>select * from r1;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | a    |
 
|  2 | b    |
 
|  3 | c    |
 
|  4 | d    |
 
|  5 | e    |
 
|  6 | f    |
 
+----+------+
 
6 rows in set (0.00 sec)
 
Slave :
 
MariaDB [r2]> show slave 'r1' status/G;
 
*************************** 1. row ***************************
 
               Slave_IO_State: Waiting for master to send event
 
                  Master_Host: 192.168.200.51
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin51.000013
 
          Read_Master_Log_Pos: 767
 
               Relay_Log_File: mysqld-relay-bin-r1.000005
 
                Relay_Log_Pos: 956
 
        Relay_Master_Log_File: mysql-bin51.000013
 
             Slave_IO_Running: Yes
 
            Slave_SQL_Running: No
 
              Replicate_Do_DB:
 
          Replicate_Ignore_DB:
 
           Replicate_Do_Table:
 
       Replicate_Ignore_Table:
 
      Replicate_Wild_Do_Table:
 
  Replicate_Wild_Ignore_Table:
 
                   Last_Errno: 1007
 
                   Last_Error: Error 'Can't create database 'r2'; database exists' on query. Default database: 'r2'. Query: 'create database r2 default charset utf8'
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 667
 
              Relay_Log_Space: 1505
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: NULL
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 1007
 
               Last_SQL_Error: Error 'Can't create database 'r2'; database exists' on query. Default database: 'r2'. Query: 'create database r2 default charset utf8'
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 1
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
1 row in set (0.00 sec)
 
MariaDB [r1]> select * from r1;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | a    |
 
|  2 | b    |
 
|  3 | c    |
 
+----+------+
 
3 rows in set (0.00 sec)
 
r1的同步失敗了,那r2可以繼續同步嗎?
 
Master 2:
 
[email protected] : r2 01:55:59>insert into r2(name) values('D'),('E'),('F');
 
Query OK, 3 rows affected (0.01 sec)
 
Records: 3  Duplicates: 0  Warnings: 0
 
[email protected] : r2 02:02:19>select * from r2;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | A    |
 
|  2 | B    |
 
|  3 | C    |
 
|  4 | D    |
 
|  5 | E    |
 
|  6 | F    |
 
+----+------+
 
6 rows in set (0.01 sec)
 
Slave:
 
MariaDB [r2]> select * from r2;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | A    |
 
|  2 | B    |
 
|  3 | C    |
 
|  4 | D    |
 
|  5 | E    |
 
|  6 | F    |
 
+----+------+
 
6 rows in set (0.00 sec)
 
上面可以得出:r1同步失敗之后,不影響r2的同步。想要r1同步正常,則需要忽略即跳過該錯誤。如:
 
MariaDB [r1]> stop slave 'r1';
 
Query OK, 0 rows affected (0.12 sec)
 
MariaDB [r1]> set @@default_master_connection='r1';  #這里是重點:指定一個通道,然后用單通道的sql_slave_skip_counter。
 
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [r1]> select @@default_master_connection;
 
+-----------------------------+
 
| @@default_master_connection |
 
+-----------------------------+
 
| r1                          |
 
+-----------------------------+
 
1 row in set (0.00 sec)
 
MariaDB [r1]> SET GLOBAL sql_slave_skip_counter =1;
 
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [r1]> start slave 'r1';
 
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [r1]> show slave 'r1' status/G;
 
*************************** 1. row ***************************
 
               Slave_IO_State: Waiting for master to send event
 
                  Master_Host: 192.168.200.51
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin51.000013
 
          Read_Master_Log_Pos: 993
 
               Relay_Log_File: mysqld-relay-bin-r1.000006
 
                Relay_Log_Pos: 396
 
        Relay_Master_Log_File: mysql-bin51.000013
 
             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: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 993
 
              Relay_Log_Space: 1731
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: 0
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 1
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
1 row in set (0.00 sec)
 
MariaDB [r1]> select * from r1;
 
+----+------+
 
| id | name |
 
+----+------+
 
|  1 | a    |
 
|  2 | b    |
 
|  3 | c    |
 
|  4 | d    |
 
|  5 | e    |
 
|  6 | f    |
 
+----+------+
 
6 rows in set (0.00 sec)
 
看到跳過/忽略錯誤之后,r1的復制就正常了。
 
從上面的測試上說明,在用多主一從的復制時,需要保證各個主的Master Schema 要唯一,不能有重復。
 
最后再看看如何初始化:
 
MariaDB [r1]> show all slaves status/G;
 
*************************** 1. row ***************************
 
              Connection_name: r1
 
              Slave_SQL_State: Slave has read all relay log; waiting for the slave I/O thread to update it
 
               Slave_IO_State: Waiting for master to send event
 
                  Master_Host: 192.168.200.51
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin51.000013
 
          Read_Master_Log_Pos: 1376
 
               Relay_Log_File: mysqld-relay-bin-r1.000006
 
                Relay_Log_Pos: 779
 
        Relay_Master_Log_File: mysql-bin51.000013
 
             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: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 1376
 
              Relay_Log_Space: 2114
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: 0
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 1
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
         Retried_transactions: 0
 
           Max_relay_log_size: 104857600
 
         Executed_log_entries: 39
 
    Slave_received_heartbeats: 4
 
       Slave_heartbeat_period: 1800.000
 
               Gtid_Slave_Pos:
 
*************************** 2. row ***************************
 
              Connection_name: r2
 
              Slave_SQL_State: Slave has read all relay log; waiting for the slave I/O thread to update it
 
               Slave_IO_State: Waiting for master to send event
 
                  Master_Host: 192.168.200.52
 
                  Master_User: rep
 
                  Master_Port: 3306
 
                Connect_Retry: 60
 
              Master_Log_File: mysql-bin_52.000106
 
          Read_Master_Log_Pos: 893
 
               Relay_Log_File: mysqld-relay-bin-r2.000005
 
                Relay_Log_Pos: 1183
 
        Relay_Master_Log_File: mysql-bin_52.000106
 
             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: 0
 
                   Last_Error:
 
                 Skip_Counter: 0
 
          Exec_Master_Log_Pos: 893
 
              Relay_Log_Space: 1633
 
              Until_Condition: None
 
               Until_Log_File:
 
                Until_Log_Pos: 0
 
           Master_SSL_Allowed: No
 
           Master_SSL_CA_File:
 
           Master_SSL_CA_Path:
 
              Master_SSL_Cert:
 
            Master_SSL_Cipher:
 
               Master_SSL_Key:
 
        Seconds_Behind_Master: 0
 
Master_SSL_Verify_Server_Cert: No
 
                Last_IO_Errno: 0
 
                Last_IO_Error:
 
               Last_SQL_Errno: 0
 
               Last_SQL_Error:
 
  Replicate_Ignore_Server_Ids:
 
             Master_Server_Id: 2
 
               Master_SSL_Crl:
 
           Master_SSL_Crlpath:
 
                   Using_Gtid: No
 
                  Gtid_IO_Pos:
 
         Retried_transactions: 0
 
           Max_relay_log_size: 104857600
 
         Executed_log_entries: 28
 
    Slave_received_heartbeats: 4
 
       Slave_heartbeat_period: 1800.000
 
               Gtid_Slave_Pos:
 
2 rows in set (0.00 sec)
 
#單個通道初始化
 
MariaDB [r1]> reset slave 'r1' all;
 
ERROR 1198 (HY000): This operation cannot be performed as you have a running slave 'r1'; run STOP SLAVE 'r1' first
 
MariaDB [r1]> stop slave 'r1';
 
Query OK, 0 rows affected (0.03 sec)
 
MariaDB [r1]> reset slave 'r1' all;
 
Query OK, 0 rows affected (0.04 sec)
 
MariaDB [r1]> stop slave 'r2';
 
Query OK, 0 rows affected (0.02 sec)
 
MariaDB [r1]> reset slave 'r2' all;
 
Query OK, 0 rows affected (0.02 sec)
 
MariaDB [r1]> show all slaves status/G;
 
Empty set (0.00 sec)
 
#所有通道初始化
 
MariaDB [r1]> stop all slaves;
 
Query OK, 0 rows affected, 2 warnings (0.05 sec)
 
MariaDB [r1]> show warnings;
 
+-------+------+--------------------+
 
| Level | Code | Message            |
 
+-------+------+--------------------+
 
| Note  | 1938 | SLAVE 'r2' stopped |
 
| Note  | 1938 | SLAVE 'r1' stopped |
 
+-------+------+--------------------+
 
2 rows in set (0.00 sec)
 
MariaDB [r1]> reset slave all;   #執行時候發現只能讓r1初始化,不能初始化r2。所以初始化還是要單通道執行。
 
總結:
 
      經過上面的測試,實現了多個主實例的數據同步到一個從實例,這個就可以把集中做分析的數據表同步到一起進行分析處理,大大減少了數據的中間處理時間和安全,這里還有一點特別注意的是,在同步數據庫的時候可以用過濾選項(Replicate_Do_Table、Replicate_Ignore_Table、Replicate_Wild_Do_Table、Replicate_Wild_Ignore_Table),看著需要同步自己需要的表,不需要把沒必要的也同步過來。

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宅男噜噜噜66国产在线观看 | 国产永久免费观看 | 69性欧美高清影院 | 成人免费一区二区三区在线观看 | h视频在线免费观看 | 毛毛片在线看 | 精国产品一区二区三区四季综 | 超碰在线97国产 | 99sesese| 蜜桃免费在线 | 日日碰日日操 | 啊~用cao嗯力cao烂我视频 | 日本在线观看一区二区 | 久久久久av69精品 | 国产小视频在线 | 国产乱free国语对白 | 欧美大胆xxxx肉体摄影 | 欧美成人黄色小视频 | 成人aaaaa片毛片按摩 | omofun 动漫在线观看 | 韩国草草影院 | 亚洲成人在线视频网站 | 欧美亚洲一区二区三区四区 | 一区视频| 亚洲电影在线观看高清免费 | 91av亚洲| 成人mm视频在线观看 | 欧美性生交xxxxx免费观看 | 毛片在线视频观看 | 色播亚洲 | 一级黄片毛片免费看 | 黄色影院一级片 | 黄网站在线播放视频免费观看 | 精品国产一区二区三区在线观看 | 久草在线资源福利站 | 超碰97人 | 久久免费激情视频 | 成人不卡 | 黄色特级一级片 | 久久精品一区二区三区四区五区 | javhdfreejaⅴhd |