<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        MySQL雙Master配置_MySQL

        來源:懂視網 責編:小采 時間:2020-11-09 20:08:51
        文檔

        MySQL雙Master配置_MySQL

        MySQL雙Master配置_MySQL:主機環境說明。 master1: 10.8.1.11 master2: 10.8.1.12 版本信息: [root@m1 ~]# mysql -V mysql Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using EditLine wrapper 1、主庫開啟bin-log功能,配置serv
        推薦度:
        導讀MySQL雙Master配置_MySQL:主機環境說明。 master1: 10.8.1.11 master2: 10.8.1.12 版本信息: [root@m1 ~]# mysql -V mysql Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using EditLine wrapper 1、主庫開啟bin-log功能,配置serv

        主機環境說明。

        master1: 10.8.1.11

        master2: 10.8.1.12

        版本信息:

        [root@m1 ~]# mysql -V

        mysql Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using EditLine wrapper

        1、主庫開啟bin-log功能,配置server-id

        修改my.cf配置文件,開啟bin-log功能,配置server-id。

         [root@m1 ~]# more /etc/my.cnf
         
         # For advice on how to change settings please see
         # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
         
         [mysqld]
         server-id = 1
         datadir = /var/lib/mysql
         log_bin = /var/lib/mysql/bin-log
         socket = /var/lib/mysql/mysql.sock
         slave_net_timeout = 60
         log-slave-updates
         slave-skip-errors=all
         skip-name-resolve
         sync_binlog=1
         auto_increment_increment=2
         auto_increment_offset=1
         
         sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
         
        #salve-net-timeout默認是3600秒,縮短時間是為了防止雙YES的假象
        #(事實上我已遇到,參考地址:http://www.cnblogs.com/billyxp/p/3470376.html)
        如果要指定同步或不同步哪些庫,可使用如下參數
        #binlog-do-db=osyunweidb #需要同步的數據庫名,如果有多個數據庫,可重復此參數,每個數據庫一行
        #binlog-ignore-db=mysql #不同步mysql系統數據庫
        

        至于這些參數的說明具體看手冊。

        紅色的部分非常重要,如果一個MASTER 掛掉的話,另外一個馬上接管。

        紫紅色的部分指的是服務器頻繁的刷新日志。這個保證了在其中一臺掛掉的話,日志刷新到另外一臺。從而保證了數據的同步

        2、確認bin-log與server-id是否開啟:

        查看命令 show variables like 'log_bin'; show variables like 'server_id';

        mysql> show variables like 'log_bin';
        +---------------+-------+
        |Variable_name | Value |
        +---------------+-------+
        |log_bin | ON |
        +---------------+-------+
        1 rowin set (0.00 sec)
        mysql>show variables like 'server_id';
        +---------------+-------+
        |Variable_name | Value |
        +---------------+-------+
        |server_id | 1 |
        +---------------+-------+
        1 rowin set (0.00 sec)

        3、創建復制授權用戶

        mysql> grant replication slave on *.* to replication@'%'identified by '123456'; #授權該用戶對所有表都能進行復制

        mysql>flush privileges; #刷新權限

        4、鎖表,記錄log-bin文件名和位置

        mysql>flush tables with read lock; #鎖定所有表,此時數據庫不能寫入數據
        QueryOK, 0 rows affected (0.05 sec)
        
        mysql>show master status; #查看最新bin-log文件及位置
        +------------------------+------------+-------------------+-------------------------+
        |File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
        +------------------------+------------+-------------------+-------------------------+
        |mysql-bin.000001 | 26314 | | |
        +------------------------+------------+-------------------+-------------------------+
        1row in set (0.00 sec)

        5、鎖表狀態全備mysql數據

        由于退出當前mysql登陸窗口,鎖表功能就失效,需克隆一個會話進行全備。

        #mysqldump-uroot -p -A -B > /tmp/mysql_bak_2015_11_17.sql

        看下備份數據大小,確認備份成功。

        [root@m1 ~]# ls -l mysql_bak_2015_11_17.sql

        -rw-r--r--. 1 root root 645327 Nov 18 06:27 mysql_bak_2015_11_17.sql

        [root@m1 ~]#

        6、解除鎖表

        mysql>unlock tables;

        或直接quit退出即可。

        7、從庫開啟bin-log功能,配置server-id

        從庫開啟bin-log功能后,待會在主上在配置同步,互為主從就完成了。

        [root@m2 ~]# vi /etc/my.cnf
         
         # For advice on how to change settings please see
         # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
         
         [mysqld]
         server-id = 2
         datadir = /var/lib/mysql
         log_bin = /var/lib/mysql/mysql-bin
         socket = /var/lib/mysql/mysql.sock
         slave_net_timeout = 60
         log-slave-updates
         slave-skip-errors=all
         skip-name-resolve
         sync_binlog=1
         auto_increment_increment=2
         auto_increment_offset=2
         
         sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
        
        #salve-net-timeout默認是3600秒,縮短時間是為了防止雙YES的假象

        #

        至于這些參數的說明具體看手冊。

        紅色的部分非常重要,如果一個MASTER 掛掉的話,另外一個馬上接管。

        紫紅色的部分指的是服務器頻繁的刷新日志。這個保證了在其中一臺掛掉的話,日志刷新到另外一臺。從而保證了數據的同步

        #/etc/init.d/mysql restart

        8、確認從庫bin-log與server-id是否開啟

        查看命令 show variables like 'log_bin'; show variables like 'server_id';

        mysql>show variables like 'log_bin';
        +---------------+-------+
        |Variable_name | Value |
        +---------------+-------+
        |log_bin | ON |
        +---------------+-------+
        1row in set (0.00 sec)
        mysql>show variables like 'server_id';
        +---------------+-------+
        |Variable_name | Value |
        +---------------+-------+
        |server_id | 2 |
        +---------------+-------+
        1row in set (0.00 sec)

        9、從庫導入主庫的全備數據

        登陸mysql導入數據

        mysql>source /root/mysql_bak_2015_11_17.sql

        10、記錄從庫bin-log信息

        因為在從庫導入全備數據時,此時主庫與從庫的內容是一致的,但是bin-log位置不一定一致。

        mysql>show master status; #查看最新bin-log文件及位置
        +------------------------+------------+-------------------+-------------------------+
        |File |Position | Binlog_Do_DB | Binlog_Ignore_DB |
        +------------------------+------------+-------------------+-------------------------+
        |mysql-bin.000003 | 2328055 | | |
        +------------------------+------------+-------------------+-------------------------+
        1row in set (0.00 sec)

        11、從庫設置同步主庫

        此處binlog文件與位置狀態,是主庫在步驟4鎖表時show master status查看的位置狀態。

        CHANGE MASTER TO 
        MASTER_HOST='10.8.1.11',
        MASTER_PORT=3306,
        MASTER_USER='replication',
        MASTER_PASSWORD='123456',
        MASTER_LOG_FILE='mysql-bin.000001',
        MASTER_LOG_POS=26314;

        12、開啟從庫同步并確認同步是否成功

        使用start slave開啟同步功能,使用show slave status\G查看同步是否成功

        mysql>start slave;
        QueryOK, 0 rows affected (0.00 sec)
        mysql>show slave status\G #\G不按表格
        輸出 ***************************1. row *************************** Slave_IO_State: Waiting formaster to send event Master_Host: 10.0.0.2 Master_User: replication Master_Port: 8306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 136270 Relay_Log_File:mysqld-relay-bin.000002 Relay_Log_Pos: 72697 Relay_Master_Log_File: mysql-bin.000001 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: 98758 Relay_Log_Space: 110366 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: 622 #查看主從同步延遲,延遲大則可能需要優化 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 1row in set (0.00 sec)

        #sql線程與IO線程都是YES,slave配置成功。

        13、主庫設置同步從庫

        由于從庫是全備導入,原先在主庫上配置的復制帳戶也同樣導入,所以這里不用在從庫上新授權復制用戶。

        從庫上的binlog文件與位置狀態,是從庫在剛導入時show master status查看到的位置狀態。

        CHANGEMASTER TO 
        MASTER_HOST='10.8.1.12',
        MASTER_PORT=3306,
        MASTER_USER='replication',
        MASTER_PASSWORD='123456',
        MASTER_LOG_FILE='mysql-bin.000003',
        MASTER_LOG_POS=2328055;
        #修改相應信息,直接把這些配置在mysql中粘貼即可。

        14、開啟同步并確認同步是否成功

        使用start slave開啟同步功能,使用show slave status\G查看同步是否成功

        mysql>start slave;
        QueryOK, 0 rows affected (0.00 sec)
        
        mysql>show slave status\G
        ***************************1. row ***************************
         Slave_IO_State: Waiting formaster to send event
         Master_Host: 172.16.0.2
         Master_User: replication
         Master_Port: 3306
         Connect_Retry: 60
         Master_Log_File: mysql-bin.000007
         Read_Master_Log_Pos: 107
         Relay_Log_File:mysqld-relay-bin.000006
         Relay_Log_Pos: 253
         Relay_Master_Log_File: mysql-bin.000007
         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: 556
         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
        1row in set (0.00 sec)

        #IO線程與sql線程都是正常。

        15、互為主從測試

        在兩臺mysql各創建一個庫,看兩邊是否都能進行同步。

        分別在主庫上執行 create database test01;

        從庫上執行create database test02;

        看兩臺數據庫上執行show databases;,看是否都有test01表和test02表。

        我的經過測試,雙主測試成功。

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        MySQL雙Master配置_MySQL

        MySQL雙Master配置_MySQL:主機環境說明。 master1: 10.8.1.11 master2: 10.8.1.12 版本信息: [root@m1 ~]# mysql -V mysql Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using EditLine wrapper 1、主庫開啟bin-log功能,配置serv
        推薦度:
        標簽: 配置 mysql master
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲午夜日韩高清一区| 99久久综合国产精品免费| 亚洲精品无码久久久久AV麻豆| 亚洲精品无码久久久久久| 野花高清在线观看免费3中文| 亚洲一卡2卡3卡4卡国产网站 | 8x网站免费入口在线观看| 亚洲AV无码成人精品区天堂 | 久久久精品国产亚洲成人满18免费网站 | 亚洲成a人片在线观看无码专区| 亚洲av日韩av永久无码电影| 国产在线98福利播放视频免费| 色五月五月丁香亚洲综合网| 亚洲国产婷婷综合在线精品| 中文永久免费观看网站| 精品国产综合成人亚洲区| 青青青国产手机频在线免费观看| 婷婷久久久亚洲欧洲日产国码AV| 国产精品1024永久免费视频| 国产日本亚洲一区二区三区| 全部免费国产潢色一级| 精品久久久久久无码免费| 亚洲第一成年男人的天堂| 无人影院手机版在线观看免费| 久久精品国产亚洲av天美18| 亚洲精品线路一在线观看| 久久久久国产精品免费网站| 亚洲人成日本在线观看| 国产乱子伦精品免费女| 久久久99精品免费观看| 亚洲va久久久久| 怡红院亚洲怡红院首页| 亚洲免费中文字幕| 黄网站色视频免费观看45分钟| 亚洲va无码专区国产乱码| 91在线视频免费播放| 日韩在线观看免费| 亚洲国产午夜精品理论片| 成人亚洲网站www在线观看| 久久国产乱子伦精品免费看| 亚洲爆乳大丰满无码专区|