MySQL5.7多源複製

来源:http://www.cnblogs.com/lizhi221/archive/2017/05/17/6868652.html
-Advertisement-
Play Games

MySQL5.7開始支持多源複製,也就是多主一從的複製架構: 使用多源複製的考慮: 1、災備作用:將各個庫彙總在一起,就算是其他庫都掛了(整個機房都無法連接了),還有最後一個救命稻草; 2、備份:直接在這個從庫中做備份,不影響線上的資料庫; 3、減少成本:不需要每個庫都做一個實例,也減少了DBA的維 ...


MySQL5.7開始支持多源複製,也就是多主一從的複製架構:

使用多源複製的考慮: 1、災備作用:將各個庫彙總在一起,就算是其他庫都掛了(整個機房都無法連接了),還有最後一個救命稻草; 2、備份:直接在這個從庫中做備份,不影響線上的資料庫; 3、減少成本:不需要每個庫都做一個實例,也減少了DBA的維護成本; 4、數據統計:後期的一些數據統計,需要將所有的庫彙總在一起。 ... ...   實驗環境: Master1:10.157.26.132:3307 Master2:10.157.26.133:3307 Slave:10.157.26.134:3307 多源複製是支持GTID和Binlog+Position,我這裡是GTID複製。   MySQL5.7的安裝這裡不再介紹,可以查看http://www.cnblogs.com/lizhi221/p/6813907.html   一、配置文件:   Master1和Master2:
#GTID
gtid-mode = on
binlog_gtid_simple_recovery=1
enforce_gtid_consistency=1
binlog_format = row
skip_slave_start = 1
log-bin = /data/mysql/mysql_3307/logs/binlog/mysql-bin
Slave:
#binlog
binlog_format = row
server-id = 1343307
log-bin = /data/mysql/mysql_3307/logs/binlog/mysql-bin
#GTID
gtid-mode = on
binlog_gtid_simple_recovery=1
enforce_gtid_consistency=1
#修改MySQL存儲master-info和relay-info的方式,即從文件存儲改為表存儲
master_info_repository=TABLE
relay_log_info_repository=TABLE
replicate_ignore_db=mysql  #忽略mysql庫的同步
skip_slave_start = 1
二、主庫創建複製賬號:
Master1:grant replication slave,replication client on *.* to sampson_132@'10.157.26.%'identified by 'sampson_132';
Master2:grant replication slave,replication client on *.* to sampson_133@'10.157.26.%'identified by 'sampson_133';
三:從庫啟動複製:
mysql> change master to master_host='10.157.26.132',master_port=3307,master_user='sampson_132',master_password='sampson_132',master_auto_position=1 for channel 'Master_132';
mysql>change master to master_host='10.157.26.133',master_port=3307,master_user='sampson_133',master_password='sampson_133',master_auto_position=1 for channel 'Master_133';
mysql>start slave;
也可以start slave for channel 'Master_132 '啟動單個channel的複製。   四:查看slave狀態 【也可以直接show slave status for channel 'Master_132' \G查看各個channel的複製狀態】
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.157.26.132
                  Master_User: sampson_132
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay_log-master_132.000002
                Relay_Log_Pos: 367
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql
           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: 154
              Relay_Log_Space: 579
              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: 1323307
                  Master_UUID: 8785129a-3ace-11e7-9f13-fa163e48cafd
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: master_132
           Master_TLS_Version:
*************************** 2. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.157.26.133
                  Master_User: sampson_133
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay_log-master_133.000002
                Relay_Log_Pos: 367
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql
           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: 154
              Relay_Log_Space: 579
              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: 1333307
                  Master_UUID: 3d5ae510-3acf-11e7-82a4-fa163e8e91ad
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: master_133
           Master_TLS_Version:
2 rows in set (0.01 sec)
通過查看performance_schema相關的表查看同步狀態:
mysql> select * from performance_schema.replication_connection_status\G
*************************** 1. row ***************************
             CHANNEL_NAME: master_132
               GROUP_NAME:
              SOURCE_UUID: 8785129a-3ace-11e7-9f13-fa163e48cafd
                THREAD_ID: 89
            SERVICE_STATE: ON
COUNT_RECEIVED_HEARTBEATS: 1
 LAST_HEARTBEAT_TIMESTAMP: 2017-05-17 16:59:45
 RECEIVED_TRANSACTION_SET:
        LAST_ERROR_NUMBER: 0
       LAST_ERROR_MESSAGE:
     LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
*************************** 2. row ***************************
             CHANNEL_NAME: master_133
               GROUP_NAME:
              SOURCE_UUID: 3d5ae510-3acf-11e7-82a4-fa163e8e91ad
                THREAD_ID: 91
            SERVICE_STATE: ON
COUNT_RECEIVED_HEARTBEATS: 1
 LAST_HEARTBEAT_TIMESTAMP: 2017-05-17 16:59:45
 RECEIVED_TRANSACTION_SET:
        LAST_ERROR_NUMBER: 0
       LAST_ERROR_MESSAGE:
     LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
2 rows in set (0.01 sec)
五、數據同步檢查: Master1建庫建表並插入數據:
mysql>CREATE DATABASE /*!32312 IF NOT EXISTS*/ `sampson_132` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
mysql>use sampson_132
mysql> create table t_132(id int primary key auto_increment,name varchar(20) not null);
mysql> insert into t_132(id,name)values(1,'132'),(2,'132'),(3,'132');
mysql> select * from t_132;
+----+------+
| id | name |
+----+------+
|  1 | 132  |
|  2 | 132  |
|  3 | 132  |
+----+------+
3 rows in set (0.00 sec)
Master2建庫建表並插入數據:
mysql> CREATE DATABASE /*!32312 IF NOT EXISTS*/ `sampson_133` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
mysql> use sampson_133
mysql> create table t_133(id int primary key auto_increment,name varchar(20) not null);
mysql> insert into t_133(id,name)values(1,'133'),(2,'133'),(3,'133');
mysql> select * from sampson_133.t_133;
+----+------+
| id | name |
+----+------+
|  1 | 133  |
|  2 | 133  |
|  3 | 133  |
+----+------+
3 rows in set (0.00 sec)
Slave查看數據是否同步:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sampson_132        |
| sampson_133        |
| sys                |
+--------------------+
6 rows in set (0.00 sec)
 
mysql> select * from sampson_132.t_132;
+----+------+
| id | name |
+----+------+
|  1 | 132  |
|  2 | 132  |
|  3 | 132  |
+----+------+
3 rows in set (0.00 sec)
 
mysql> select * from sampson_133.t_133;
+----+------+
| id | name |
+----+------+
|  1 | 133  |
|  2 | 133  |
|  3 | 133  |
+----+------+
3 rows in set (0.00 sec)

再次查看從庫狀態:

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.157.26.132
                  Master_User: sampson_132
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 930
               Relay_Log_File: relay_log-master_132.000002
                Relay_Log_Pos: 1143
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql
           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: 930
              Relay_Log_Space: 1355
              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: 1323307
                  Master_UUID: 8785129a-3ace-11e7-9f13-fa163e48cafd
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set: 8785129a-3ace-11e7-9f13-fa163e48cafd:1-3
            Executed_Gtid_Set: 3d5ae510-3acf-11e7-82a4-fa163e8e91ad:1-3,
8785129a-3ace-11e7-9f13-fa163e48cafd:1-3
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: master_132
           Master_TLS_Version:
*************************** 2. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.157.26.133
                  Master_User: sampson_133
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 930
               Relay_Log_File: relay_log-master_133.000002
                Relay_Log_Pos: 1143
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql
           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: 930
              Relay_Log_Space: 1355
              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: 1333307
                  Master_UUID: 3d5ae510-3acf-11e7-82a4-fa163e8e91ad
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set: 3d5ae510-3acf-11e7-82a4-fa163e8e91ad:1-3
            Executed_Gtid_Set: 3d5ae510-3acf-11e7-82a4-fa163e8e91ad:1-3,
8785129a-3ace-11e7-9f13-fa163e48cafd:1-3
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name: master_133
           Master_TLS_Version:
2 rows in set (0.00 sec)

 

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 上面的是修改UIAlertViewController的title和message字體的大小和顏色,採用的是修改attributedString其中的NSForegroundColorAttributeName顏色屬性和NSFontAttributeName字體大小屬性。UIAlertViewCon ...
  • 準備工作: 1.下載java sdk 配置好java 環境 2.下載android sdk 跟 android studio 並配置好環境 1.查看平臺支持,添加android平臺 首先命令提示符進入到所在項目文件夾下 查看系統所支持 的平臺 因為我已經配置好環境了,所以在這裡我們能看到 andro ...
  • 回到目錄 關於redis連接數過高的解釋 對於node.js開發環境里,使用傳統的redis或者使用ioredis都是不錯的選擇,而在處理大數據請求程中,偶爾出現了連接池( redis服務端的最大可用連接數,預設為1萬)不夠用的情況,一般的提示如下: 在redis-cli上輸入info命令也可以進行 ...
  • 一行數據是如何來存儲的呢? 變長列與定長列,NULL與NOT NULL,實際是如何整理存放到 8k的數據頁上呢? 對錶格進行增減列,修改長度,添加預設值等DDL SQL,對行存儲結構又會有怎麼樣的影響呢? 什麼是大對象,什麼是行溢出,存儲引擎是如何處理它們呢? 如果轉載,請註明博文來源: www.c ...
  • 1. datetime(年月日時分秒) 格式:‘YYY-MM-DD HH:MM:SS’。 占用:8位元組 範圍:1000-01-01 00:00:00 到 9999-12-31 23:59:59。 tip:可以接收任意分隔符的日期,主要是判斷日期是否正確,是否在正確範圍內。 但是,不通用的分隔符可讀性 ...
  • 上一篇 講了在windows系統下的安裝和啟動,本文主要講怎麼建庫、刪庫、插入、更新 在講之前我們說一下mongoDB的一些基本概念,我們對比關係型資料庫能更直觀的理解 1.我們首先要啟動mongoDB伺服器,怎麼啟動看上一篇 2.打開shell,我們到mongoDB的安裝目錄下找到bin文件夾,進 ...
  • 本文從零開始一步一步介紹如何在Ubuntu上搭建SQL Server 2017,包括安裝系統、安裝SQL等相關步驟和方法(僅供測試學習之用,基礎篇)。 一. 創建Ubuntu系統(Create Ubuntu System) 1. 前提準備 由於本文主要研究SQL Server 2017在Linux上 ...
  • MySQL中的explain命令顯示了mysql如何使用索引來處理select語句以及連接表。explain顯示的信息可以幫助選擇更好的索引和寫出更優化的查詢語句。 1.EXPLAIN的使用方法:在select語句前加上explain就可以了。 如:explain select surname,fi ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...