溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL主從復制的配置及原理

發(fā)布時間:2020-08-03 08:15:37 來源:網(wǎng)絡 閱讀:497 作者:damiahu 欄目:數(shù)據(jù)庫

-----------------------------------------------------------

mysql 5.5   環(huán)境用的數(shù)據(jù)庫可的多實例

-----------------------------------------------------------

mysql 主從復制原理圖

MySQL主從復制的配置及原理

mysql 主從復制開始配置  環(huán)境是一個數(shù)據(jù)庫多個實例 3306端口為主 3307端口為從

1 開始配置主庫和從庫的my.cnf配置文件

配置主數(shù)據(jù)庫的my.cnf文件(3306)

server-id       = 1

log-bin=mysql-bin
配置從數(shù)據(jù)庫的my.cnf文件(3307)

server-id       = 2

#log-bin=mysql-bin

然后重啟數(shù)據(jù)庫

2登錄主數(shù)據(jù)庫給從數(shù)據(jù)庫分配權(quán)限用戶

grant replication slave on *.* to 'repl'@'192.168.1.17' identified by '123456';

3 鎖表并且導出主庫里的數(shù)據(jù)

 flush table with read lock;

show master status;查看bin-log的位置狀態(tài)

+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 |      264 |              |                  |
+------------------+----------+--------------+------------------+


/usr/local/mysql/bin/mysqldump  -uroot -plampol -S /tmp/mysql3306.sock --events  -A  -B > /tmp/master.sql;

4 進從數(shù)據(jù)庫導入主數(shù)據(jù)庫的數(shù)據(jù)

source /tmp/master.sql

5進從庫執(zhí)行

change master to master_host='192.168.1.17',
      master_port=3306,
      master_user='repl',
      master_password='123456',
      master_log_file='mysql-bin.000009',
      master_log_pos=264;

6 從庫開啟同步開關(guān) start slave

  • show slave status \G;
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.1.17
                      Master_User: repl
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000009
              Read_Master_Log_Pos: 500
                   Relay_Log_File: bogon-relay-bin.000002
                    Relay_Log_Pos: 489
            Relay_Master_Log_File: mysql-bin.000009
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes  //兩個yes就ok了主從配置成功

                  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: 500
                  Relay_Log_Space: 645
                  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

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI