1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      MySQL-5.5主從復(fù)制原理是什么及如何配置

      下文主要給大家?guī)鞰ySQL-5.5主從復(fù)制原理是什么及如何配置,希望MySQL-5.5主從復(fù)制原理是什么及如何配置能夠帶給大家實(shí)際用處,這也是我編輯這篇文章的主要目的。好了,廢話不多說,大家直接看下文吧。

      創(chuàng)新互聯(lián)公司從2013年創(chuàng)立,先為當(dāng)涂等服務(wù)建站,當(dāng)涂等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為當(dāng)涂企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

      環(huán)境:

      [root@SQL-M ~]# cat /etc/redhat-release 

      CentOS release 6.8 (Final)

      [root@SQL-M ~]# uname -r

      2.6.32-642.el6.x86_64

      Master  IP  192.168.0.88/24  eth0

      Slave   IP  192.168.0.90/24  eth0

      MySQL-5.5主從復(fù)制原理是什么及如何配置

      主從復(fù)制原理:

           當(dāng)用戶對(duì)數(shù)據(jù)有增刪改操作時(shí),主庫本地存一份,另外會(huì)把用戶增刪改的操作記錄在 binlog 里面(binlog是實(shí)現(xiàn)主從復(fù)制的基礎(chǔ)),binlog的索引文件是mysql-bin.index;從庫的IO線程根據(jù)本地master.info文件里面記錄的ip、port、user、password、binlog name、pos連接主庫IO線程,主庫判斷信息,正確就返回?cái)?shù)據(jù),返回的數(shù)據(jù)里包括下次復(fù)制起始點(diǎn)的binlog名稱和pos值;從庫收到數(shù)據(jù)后寫入relay-log,同時(shí)把下次復(fù)制起始點(diǎn)的binlog名稱和pos值刷新進(jìn)master.info文件,之后從庫的SQL線程讀取relay-log里面的SQL語句,執(zhí)行語句將數(shù)據(jù)寫入本地磁盤,主從復(fù)制完成。

      配置要點(diǎn):

      主從復(fù)制,主庫開啟 bin-log 從庫開啟 relay-log ,主從 server-id 不能相同。

      Master 配置:

      [root@SQL-M ~]# vim /etc/my.cnf 
      [client]
      port=3306
      socket= /usr/local/mysql/mysql.sock
      default-character-set = utf8
      
      [mysql]
      no-auto-rehash
      prompt=Master>\_
      
      [mysqld]
      user    = mysql
      port    = 3306
      socket  = /usr/local/mysql/mysql.sock
      basedir = /usr/local/mysql
      datadir = /usr/local/mysql/data
      character-set-server = utf8
      skip-character-set-client-handshake 
      init-connect = 'SET NAMES utf8' 
      open_files_limit=1024
      back_log = 600
      max_connections = 800
      max_connect_errors = 3000
      table_cache = 614
      external-locking = FALSE
      max_allowed_packet =8M
      sort_buffer_size = 1M
      join_buffer_size = 1M
      thread_cache_size = 100
      thread_concurrency = 2
      query_cache_size = 2M
      query_cache_limit = 1M
      query_cache_min_res_unit = 2k
      thread_stack = 192K
      tmp_table_size = 2M
      max_heap_table_size = 2M
      
      server-id = 1              <<---  id 為 1
      log-bin = /usr/local/mysql/data/mysql-bin   <<--- 開啟 bin log
      binlog_cache_size = 1M
      max_binlog_cache_size = 1M
      max_binlog_size = 2M
      expire_logs_days = 7
      key_buffer_size = 16M
      read_buffer_size = 1M
      read_rnd_buffer_size = 1M
      bulk_insert_buffer_size = 1M
      lower_case_table_names = 1
      skip-name-resolve
      slave-skip-errors = 1032,1062,1007,1008,1050
      replicate-ignore-db=mysql
      
      innodb_additional_mem_pool_size = 4M
      innodb_buffer_pool_size = 16M
      innodb_file_io_threads = 4
      innodb_thread_concurrency = 8
      innodb_flush_log_at_trx_commit = 2
      innodb_log_buffer_size = 2M
      innodb_log_file_size = 4M
      innodb_log_files_in_group = 3
      innodb_max_dirty_pages_pct = 90
      innodb_lock_wait_timeout = 120
      innodb_file_per_table = 0
      
      [mysqldump]
      quick
      max_allowed_packet = 2M
      
      [mysqld_safe]
      log-error=/var/log/mysqld.log
      pid-file=/usr/local/mysql/mysqld.pid

      Slave 配置:

      [root@SQL-S1 ~]# vim /etc/my.cnf 
      [client]
      port=3306
      socket= /usr/local/mysql/mysql.sock
      default-character-set = utf8
      
      [mysql]
      no-auto-rehash
      prompt=Slave>\_
      
      [mysqld]
      user    = mysql
      port    = 3306
      socket  = /usr/local/mysql/mysql.sock
      basedir = /usr/local/mysql
      datadir = /usr/local/mysql/data
      character-set-server = utf8
      skip-character-set-client-handshake
      init-connect = 'SET NAMES utf8'
      open_files_limit=1024
      back_log = 600
      max_connections = 800
      max_connect_errors = 3000
      table_cache = 614
      external-locking = FALSE
      max_allowed_packet =8M
      sort_buffer_size = 1M
      join_buffer_size = 1M
      thread_cache_size = 100
      thread_concurrency = 2
      query_cache_size = 2M
      query_cache_limit = 1M
      query_cache_min_res_unit = 2k
      thread_stack = 192K
      tmp_table_size = 2M
      max_heap_table_size = 2M
      
      server-id = 2                  <<--- id 為 2
      relay-log =/usr/local/mysql/data/relay-bin    <<--- 開啟 relay log
      relay-log-info-file = /usr/local/mysql/data/relay-log.info
      
      key_buffer_size = 16M
      read_buffer_size = 1M
      read_rnd_buffer_size = 1M
      bulk_insert_buffer_size = 1M
      lower_case_table_names = 1
      skip-name-resolve
      slave-skip-errors = 1032,1062,1007,1008,1050
      replicate-ignore-db=mysql
      
      innodb_additional_mem_pool_size = 4M
      innodb_buffer_pool_size = 16M
      innodb_file_io_threads = 4
      innodb_thread_concurrency = 8
      innodb_flush_log_at_trx_commit = 2
      innodb_log_buffer_size = 2M
      innodb_log_file_size = 4M
      innodb_log_files_in_group = 3
      innodb_max_dirty_pages_pct = 90
      innodb_lock_wait_timeout = 120
      innodb_file_per_table = 0
      
      [mysqldump]
      quick
      max_allowed_packet = 2M
      
      [mysqld_safe]
      log-error=/var/log/mysqld.log
      pid-file=/var/run/mysqld/mysqld.pid

      Master 端準(zhǔn)備數(shù)據(jù)和創(chuàng)建復(fù)制用戶

      [root@SQL-M ~]# mysql -uroot -p
      Enter password: 
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 5.5.55-log MySQL Community Server (GPL)
      
      Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
      
      Oracle is a registered trademark of Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their respective
      owners.
      
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      Master>
        ster> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | performance_schema |
      | school             |
      +--------------------+
      4 rows in set (0.00 sec)
      
      Master> use school;
      Database changed
      Master>
      Master> show tables;
      +------------------+
      | Tables_in_school |
      +------------------+
      | student          |
      | test01           |
      | test02           |
      +------------------+
      3 rows in set (0.00 sec)
      
      Master> select * from student;
      +----+--------+-----+-----+
      | id | name   | sex | age |
      +----+--------+-----+-----+
      |  1 | 小東   | 男  |   0 |
      |  3 | 小北   | 女  |  12 |
      +----+--------+-----+-----+
      2 rows in set (0.00 sec)
      
      Master> grant replication slave on *.* to rep@'192.168.0.%' identified by '123';  # 創(chuàng)建專門用于主從復(fù)制的用戶
      Query OK, 0 rows affected (0.00 sec)   
      
      Master> select user,host from mysql.user;                                       
      +------+-------------+
      | user | host        |
      +------+-------------+
      | root | 127.0.0.1   |
      | rep  | 192.168.0.% |
      | root | localhost   |
      +------+-------------+
      3 rows in set (0.00 sec)
      
      Master> show grants for replicaton@'192.168.0.%';
      ERROR 1141 (42000): There is no such grant defined for user 'replicaton' on host '192.168.0.%'
      Master> show grants for rep@'192.168.0.%';       
      +--------------------------------------------------------------------------------------------------------------------------+
      | Grants for rep@192.168.0.%                                                                                               |
      +--------------------------------------------------------------------------------------------------------------------------+
      | GRANT REPLICATION SLAVE ON *.* TO 'rep'@'192.168.0.%' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' |
      +--------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)

      slave 端沒有數(shù)據(jù),處于初始狀態(tài)

      [root@SQL-S1 ~]# mysql
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 5.5.55 MySQL Community Server (GPL)
      
      Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
      
      Oracle is a registered trademark of Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their respective
      owners.
      
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      Slave01> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | performance_schema |
      | test               |
      +--------------------+
      4 rows in set (0.00 sec)

      master 端用 mysqldump 導(dǎo)出數(shù)據(jù)

      由于 mysqldump 是邏輯備份程序,所以要確保 MySQL 服務(wù)是啟動(dòng)狀態(tài)。

      [root@SQL-M ~]# mysqldump -uroot -p -A -B -F --master-data=1 --events >/tmp/sql_full_back.sql 
      Enter password: 
      
      [root@SQL-M ~]# ll -h /tmp/
      total 152K
      -rw-r--r-- 1 root root 151K Apr 23 12:48 sql_full_back.sql

      mysqldump 參數(shù):

      -A  備份所有庫表
      -B  在導(dǎo)出的 sql 文件里加入建庫語句,從庫導(dǎo)入文件時(shí)就省事很多
      -F  刷新 bin log,這個(gè)在增量恢復(fù)時(shí)有用
      --master-data=1 這個(gè)參數(shù)的作用是在導(dǎo)出的 sql 文件里會(huì)加入一條語句“CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.xxxxxx', MASTER_LOG_POS=xxx;” ,這樣在從庫導(dǎo)入數(shù)據(jù)后執(zhí)行 CHANGE MASTER 時(shí)就不用加上bin-log和pos值了;=2 則是注釋。
      --events  忽略警告  Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
      
      數(shù)據(jù)量大可以備份時(shí)gzip壓縮:
      mysqldump -uroot -p -A -B -F --master-data=1 --events|gzip >/tmp/sql_full_back.sql.gz

      把備份文件 scp 到從庫

      [root@SQL-M ~]# scp /tmp/sql_full_back.sql 192.168.0.90:/tmp/
      The authenticity of host '192.168.0.90 (192.168.0.90)' can't be established.
      RSA key fingerprint is fb:9f:50:cd:ac:59:8b:a3:83:83:95:7c:62:d1:64:d2.
      Are you sure you want to continue connecting (yes/no)? yes
      Warning: Permanently added '192.168.0.90' (RSA) to the list of known hosts.
      root@192.168.0.90's password: 
      sql_full_back.sql                              100%  546KB 546.1KB/s   00:00

      從庫導(dǎo)入備份文件并檢查

      [root@SQL-S1 ~]# ll /tmp/
      total 548
      -rw-r--r-- 1 root root 559192 Apr 23 13:10 sql_full_back.sql
      [root@SQL-S1 ~]# 
      [root@SQL-S1 ~]# mysql -uroot -p  show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | performance_schema |
      | school             |
      +--------------------+
      4 rows in set (0.00 sec)
      
      Slave> 
      Slave> use school;
      Database changed
      Slave> show tables;
      +------------------+
      | Tables_in_school |
      +------------------+
      | student          |
      | test01           |
      | test02           |
      +------------------+
      3 rows in set (0.00 sec)
      
      Slave> select * from student;
      +----+--------+-----+-----+
      | id | name   | sex | age |
      +----+--------+-----+-----+
      |  1 | 小東   | 男  |   0 |
      |  3 | 小北   | 女  |  12 |
      +----+--------+-----+-----+
      2 rows in set (0.00 sec)

      從庫導(dǎo)入備份文件檢查成功后 CHANGE MASTER

      Slave> CHANGE MASTER TO  MASTER_HOST='192.168.0.88',MASTER_PORT=3306,MASTER_USER='rep',MASTER_PASSWORD='123';
      Query OK, 0 rows affected (0.01 sec)
      
      Slave> start slave;       # 啟動(dòng) slave
      Query OK, 0 rows affected (0.00 sec)
      
      Slave> show slave status\G  # 查看狀態(tài)
      *************************** 1. row ***************************
                     Slave_IO_State: Waiting for master to send event
                        Master_Host: 192.168.0.88
                        Master_User: rep
                        Master_Port: 3306
                      Connect_Retry: 60
                    Master_Log_File: mysql-bin.000016
                Read_Master_Log_Pos: 297
                     Relay_Log_File: relay-bin.000002
                      Relay_Log_Pos: 253
              Relay_Master_Log_File: mysql-bin.000016
                   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: 297
                    Relay_Log_Space: 403
                    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
      1 row in set (0.00 sec)

      slave 的狀態(tài)判斷:

      Slave_IO_Running: Yes    # IO線程負(fù)責(zé)與主庫通信傳輸數(shù)據(jù)
      Slave_SQL_Running: Yes   # SQL線程,讀取中繼日志(rely-log),再把數(shù)據(jù)寫入本地存儲(chǔ)
      Seconds_Behind_Master: 0  # 延遲時(shí)間,從主獲取數(shù)據(jù)的延遲時(shí)間,

      這三個(gè)參數(shù)是主從復(fù)制健康檢查的監(jiān)控的重點(diǎn)。

      主庫查看線程狀態(tài)

      Master> show processlist; 
      +----+------+--------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+
      | Id | User | Host               | db   | Command     | Time | State                                                                 | Info             |
      +----+------+--------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+
      | 27 | root | localhost          | NULL | Query       |    0 | NULL                                                                  | show processlist |
      | 29 | rep  | 192.168.0.90:64017 | NULL | Binlog Dump |  497 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL             |
      +----+------+--------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+
      2 rows in set (0.00 sec)

      測試主從復(fù)制

      Master 添加數(shù)據(jù)

      Master> use school;
      Database changed
      
      Master> select * from student;
      +----+--------+-----+-----+
      | id | name   | sex | age |
      +----+--------+-----+-----+
      |  1 | 小東   | 男  |   0 |
      |  3 | 小北   | 女  |  12 |
      +----+--------+-----+-----+
      2 rows in set (0.00 sec)
      
      Master> insert into student values(4,'楠楠','男',15);   # 插入新數(shù)據(jù)
      Query OK, 1 row affected (0.00 sec)
      
      Master> select * from student;                       
      +----+--------+-----+-----+
      | id | name   | sex | age |
      +----+--------+-----+-----+
      |  1 | 小東   | 男  |   0 |
      |  3 | 小北   | 女  |  12 |
      |  4 | 楠楠   | 男  |  15 |
      +----+--------+-----+-----+
      3 rows in set (0.00 sec)

      Slave 端檢查

      Slave> use school;
      Database changed
      
      Slave> show tables;
      +------------------+
      | Tables_in_school |
      +------------------+
      | student          |
      | test01           |
      | test02           |
      +------------------+
      3 rows in set (0.00 sec)
      
      Slave> select * from student;
      +----+--------+-----+-----+
      | id | name   | sex | age |
      +----+--------+-----+-----+
      |  1 | 小東   | 男  |   0 |
      |  3 | 小北   | 女  |  12 |
      |  4 | 楠楠   | 男  |  15 |    <<---- 可以看到新的數(shù)據(jù)已經(jīng)復(fù)制到位
      +----+--------+-----+-----+
      3 rows in set (0.00 sec)

      以上主從復(fù)制配置完成

      =====================  開啟半同步模式  =========================

      主從復(fù)制實(shí)際是異步的過程:

      Master IO_thread  --> Slave IO_thread -->Slave SQL_thread -->Slave localdisk

      Master IO_thread 把數(shù)據(jù)交給 Slave IO_thread 之后就不管了,后面的數(shù)據(jù)存儲(chǔ)有沒有成功Master是不知道的,這樣對(duì)數(shù)據(jù)來說顯然是不夠安全的,無法保證數(shù)據(jù)完整正確地存儲(chǔ)在Slave端。

      半同步復(fù)制

         介于異步復(fù)制和全同步復(fù)制之間,主庫在執(zhí)行完客戶端提交的事務(wù)后不是立刻返回給客戶端,而是等待至少一個(gè)從庫接收到并寫到relay log中才返回給客戶端。相對(duì)于異步復(fù)制,半同步復(fù)制提高了數(shù)據(jù)的安全性,同時(shí)它也造成了一定程度的延遲,這個(gè)延遲最少是一個(gè)TCP/IP往返的時(shí)間。所以,半同步復(fù)制最好在低延時(shí)的網(wǎng)絡(luò)中使用。

         半同步是以已經(jīng)實(shí)現(xiàn)主從復(fù)制為前提,并且MySQL版本為5.5及以上。

      實(shí)現(xiàn)半同步的插件:

      [root@SQL-M ~]# ll /usr/local/mysql/lib/plugin/
      -rwxr-xr-x 1 mysql mysql 170878 Mar 18 13:14 semisync_master.so
      -rwxr-xr-x 1 mysql mysql  88959 Mar 18 13:14 semisync_slave.so

      很清楚,一個(gè)Master用的,一個(gè)Slave用的。

      Master 端操作

      Master> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';  # 安裝插件
      Query OK, 0 rows affected (0.13 sec)    
      
      Master> SET GLOBAL rpl_semi_sync_master_enabled = 1;    # 啟用插件
      Query OK, 0 rows affected (0.00 sec)
      
      Master> show status like 'Rpl_semi_sync_master_status';
      +-----------------------------+-------+
      | Variable_name               | Value |
      +-----------------------------+-------+
      | Rpl_semi_sync_master_status | ON    |
      +-----------------------------+-------+
      1 row in set (0.00 sec)
      Master> show variables like 'rpl%';
      +------------------------------------+-------+
      | Variable_name                      | Value |
      +------------------------------------+-------+
      | rpl_recovery_rank                  | 0     |
      | rpl_semi_sync_master_enabled       | ON    |
      | rpl_semi_sync_master_timeout       | 10000 |    <<--- 默認(rèn)超時(shí),單位毫秒;數(shù)據(jù)傳輸超時(shí)會(huì)自動(dòng)轉(zhuǎn)為異步復(fù)制,傳輸正常后會(huì)自動(dòng)恢復(fù)為半同步。
      | rpl_semi_sync_master_trace_level   | 32    |
      | rpl_semi_sync_master_wait_no_slave | ON    |
      +------------------------------------+-------+
      5 rows in set (0.00 sec)
      
      Master> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS  WHERE PLUGIN_NAME LIKE '%semi%';
      +----------------------+---------------+
      | PLUGIN_NAME          | PLUGIN_STATUS |
      +----------------------+---------------+
      | rpl_semi_sync_master | ACTIVE        |
      +----------------------+---------------+
      1 row in set (0.00 sec)
      
      Master> show status like 'rpl%'; 
      +--------------------------------------------+-------------+
      | Variable_name                              | Value       |
      +--------------------------------------------+-------------+
      | Rpl_semi_sync_master_clients               | 0           |   <<--- 還沒有從庫連接
      | Rpl_semi_sync_master_net_avg_wait_time     | 0           |
      | Rpl_semi_sync_master_net_wait_time         | 0           |
      | Rpl_semi_sync_master_net_waits             | 0           |
      | Rpl_semi_sync_master_no_times              | 0           |
      | Rpl_semi_sync_master_no_tx                 | 0           |
      | Rpl_semi_sync_master_status                | ON          |
      | Rpl_semi_sync_master_timefunc_failures     | 0           |
      | Rpl_semi_sync_master_tx_avg_wait_time      | 0           |
      | Rpl_semi_sync_master_tx_wait_time          | 0           |
      | Rpl_semi_sync_master_tx_waits              | 0           |
      | Rpl_semi_sync_master_wait_pos_backtraverse | 0           |
      | Rpl_semi_sync_master_wait_sessions         | 0           |
      | Rpl_semi_sync_master_yes_tx                | 0           |
      | Rpl_status                                 | AUTH_MASTER |
      +--------------------------------------------+-------------+
      15 rows in set (0.00 sec)

      Slave 端操作

      Slave> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';  # 安裝slave插件
      Query OK, 0 rows affected (0.11 sec)
      
      Slave> SET GLOBAL rpl_semi_sync_slave_enabled = 1;      # 啟用插件
      Query OK, 0 rows affected (0.00 sec)
      
      Slave> show status like 'Rpl_semi_sync_slave_status';
      +----------------------------+-------+
      | Variable_name              | Value |
      +----------------------------+-------+
      | Rpl_semi_sync_slave_status | OFF   |
      +----------------------------+-------+
      1 row in set (0.00 sec)
      
      Slave>  stop slave;               # 重啟slave
      Query OK, 0 rows affected (0.00 sec)
      
      Slave>  start slave;
      Query OK, 0 rows affected (0.00 sec)
      
      Slave> show status like 'Rpl_semi_sync_slave_status';
      +----------------------------+-------+
      | Variable_name              | Value |
      +----------------------------+-------+
      | Rpl_semi_sync_slave_status | ON    |
      +----------------------------+-------+
      1 row in set (0.00 sec)
      
      Slave> show status like 'rpl%';
      +----------------------------+-------------+
      | Variable_name              | Value       |
      +----------------------------+-------------+
      | Rpl_semi_sync_slave_status | ON          |
      | Rpl_status                 | AUTH_MASTER |
      +----------------------------+-------------+
      2 rows in set (0.00 sec)
      
      Slave> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS  WHERE PLUGIN_NAME LIKE '%semi%';
      +---------------------+---------------+
      | PLUGIN_NAME         | PLUGIN_STATUS |
      +---------------------+---------------+
      | rpl_semi_sync_slave | ACTIVE        |
      +---------------------+---------------+
      1 row in set (0.00 sec)

      Master端檢查從庫連接情況

      Master> show status like 'rpl%';
      +--------------------------------------------+-------------+
      | Variable_name                              | Value       |
      +--------------------------------------------+-------------+
      | Rpl_semi_sync_master_clients               | 1           |   <<--- 可以看到有一個(gè)從庫已經(jīng)成功連接
      | Rpl_semi_sync_master_net_avg_wait_time     | 0           |
      | Rpl_semi_sync_master_net_wait_time         | 0           |
      | Rpl_semi_sync_master_net_waits             | 0           |
      | Rpl_semi_sync_master_no_times              | 0           |
      | Rpl_semi_sync_master_no_tx                 | 0           |
      | Rpl_semi_sync_master_status                | ON          |
      | Rpl_semi_sync_master_timefunc_failures     | 0           |
      | Rpl_semi_sync_master_tx_avg_wait_time      | 0           |
      | Rpl_semi_sync_master_tx_wait_time          | 0           |
      | Rpl_semi_sync_master_tx_waits              | 0           |
      | Rpl_semi_sync_master_wait_pos_backtraverse | 0           |
      | Rpl_semi_sync_master_wait_sessions         | 0           |
      | Rpl_semi_sync_master_yes_tx                | 0           |
      | Rpl_status                                 | AUTH_MASTER |
      +--------------------------------------------+-------------+
      15 rows in set (0.00 sec)

      半同步測試

      正常情況下master插入數(shù)據(jù)的速度很快

      Master> insert into student values(6,'小欣','女',13);

      Query OK, 1 row affected (0.00 sec)     <<--- 速度很快

      Master> insert into student values(7,'小倩','女',13);

      Query OK, 1 row affected (0.00 sec)     <<--- 一樣

      接下來模仿從庫故障,停掉slave的 IO 線程

      Slave> stop slave io_thread;

      Query OK, 0 rows affected (0.00 sec)

      Master 再插入數(shù)據(jù)

      Master> insert into student values(8,'姍姍','女',13);

      Query OK, 1 row affected (10.00 sec)     <<---  超時(shí)了,自動(dòng)轉(zhuǎn)為異步

      從庫恢復(fù)正常

      Slave> start slave io_thread;

      Query OK, 0 rows affected (0.00 sec)

      主庫插入數(shù)據(jù)

      Master> insert into student values(9,'小強(qiáng)','男',13);

      Query OK, 1 row affected (0.00 sec)     <<--- 自動(dòng)恢復(fù)為半同步了

      ============================================================

      到此半同步配置完成

      對(duì)于以上關(guān)于MySQL-5.5主從復(fù)制原理是什么及如何配置,大家是不是覺得非常有幫助。如果需要了解更多內(nèi)容,請(qǐng)繼續(xù)關(guān)注我們的行業(yè)資訊,相信你會(huì)喜歡上這些內(nèi)容的。


      網(wǎng)站標(biāo)題:MySQL-5.5主從復(fù)制原理是什么及如何配置
      文章URL:http://www.ef60e0e.cn/article/ieoeep.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        安图县| 武隆县| 玉林市| 高青县| 仙桃市| 木兰县| 朔州市| 平山县| 大连市| 汝城县| 慈利县| 阿克苏市| 博爱县| 鲁山县| 乌审旗| 武强县| 东平县| 都安| 同江市| 平泉县| 汽车| 龙口市| 白水县| 周宁县| 松溪县| 广西| 通州区| 万安县| 孙吴县| 郑州市| 长治县| 霍州市| 文安县| 二连浩特市| 隆尧县| 澳门| 县级市| 阿鲁科尔沁旗| 庆城县| 朔州市| 城步|