MySQL5.5復(fù)制搭建的示例分析-創(chuàng)新互聯(lián)

這篇文章主要為大家展示了“MySQL 5.5 復(fù)制搭建的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“MySQL 5.5 復(fù)制搭建的示例分析”這篇文章吧。

站在用戶的角度思考問題,與客戶深入溝通,找到龍陵網(wǎng)站設(shè)計與龍陵網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站設(shè)計制作、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋龍陵地區(qū)。

--Master 192.168.78.139
--Slave 192.168.78.137

--在Slave安裝好MySQL軟件,安裝流程可以參考源碼安裝文章
http://blog.itpub.net/26506993/viewspace-2072859/

--Master關(guān)閉數(shù)據(jù)庫,并拷貝數(shù)據(jù)文件到Slave
[root@localhost backup]# /software/bin/mysqladmin -usystem -p'Mysql#2015' shutdown
[root@localhost backup]# 160426 19:50:32 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    /software/bin/mysqld_safe --defaults-file=/etc/my.cnf  (wd: /data)
(wd now: /backup)
[root@localhost backup]# ps -ef|grep 3306
root     20319 55613  0 19:50 pts/2    00:00:00 grep 3306

[root@localhost /]# zip -r /install/mysql_data_20160427.zip /data/

[root@localhost install]# scp /install/mysql_data_20160427.zip root@192.168.78.137:/install/
The authenticity of host '192.168.78.137 (192.168.78.137)' can't be established.
RSA key fingerprint is 4a:41:41:4b:4b:83:ea:cc:4b:56:bb:20:0a:8c:88:ce.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.78.137' (RSA) to the list of known hosts.

root@192.168.78.137's password:
mysql_data_20160427.zip                                                                                                    100% 5053KB   4.9MB/s   00:01  

--Slave,將傳輸過來的數(shù)據(jù)文件解壓到Slave所要使用的數(shù)據(jù)文件目錄
[root@localhost install]# mkdir /mysql_data
[root@localhost install]# unzip -d /mysql_data/ /install/mysql_data_20160427.zip
[root@localhost install]# chown -R mysql.mysql /mysql_data/

--編輯Master的配置文件
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin

--啟動Master的Mysql數(shù)據(jù)庫
[root@localhost backup]# /software/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 20592
[root@localhost backup]# 160426 20:32:49 mysqld_safe Logging to '/log/err.log'.
160426 20:32:49 mysqld_safe Starting mysqld daemon with databases from /data

--在Master數(shù)據(jù)庫上面創(chuàng)建復(fù)制專用賬戶
mysql> grant replication slave on *.* to 'repl'@'192.168.78.%' identified by 'Mysql#2015';
Query OK, 0 rows affected (0.04 sec)

--查看Master當(dāng)前的日志名稱和位置,用于下面在Slave的change master to命令
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000008 |      256 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

--配置Slave的配置文件
[root@localhost data]# vim /etc/my.cnf
# Log
server-id = 200
log-bin = /log/binlog/mysql-bin
relay-log = /log/binlog/mysqld-relay-bin
relay-log-index = /log/binlog/product-mysql-relay-index
datadir = /mysql_data/data

--啟動Slave的數(shù)據(jù)庫服務(wù)
[root@localhost mysql]# /data/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 22611
[root@localhost mysql]# 160426 22:53:18 mysqld_safe Logging to '/log/err.log'.
160426 22:53:18 mysqld_safe Starting mysqld daemon with databases from /mysql_data/data

--在Slave配置Slave到Master的連接
通過CHANGE MASTER TO語句來設(shè)置Slave連接到Master服務(wù)器的參數(shù),來使Slave讀取Master的二進(jìn)制日志和Slave的relay日志。

mysql> change master to
    -> master_host='192.168.78.139',
    -> master_port=3306,
    -> master_user='repl',
    -> master_password='Mysql#2015',
    -> master_log_file='mysql-bin.000008',
    -> master_log_pos=256;
Query OK, 0 rows affected (0.16 sec)

參數(shù)含義:

master_host 指定連接的Master主機(jī)
master_port 指定連接的Master的端口
master_user 指定連接的Master的復(fù)制專用賬戶
master_password 指定連接的Master的復(fù)制專用賬戶的密碼
master_log_file Master當(dāng)前的日志名稱
master_log_pos Master當(dāng)前的日志位置

--Master釋放全局只讀鎖
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

--查看Slave的狀態(tài)
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 192.168.78.139
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000008
          Read_Master_Log_Pos: 256
               Relay_Log_File: mysqld-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000008
             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: 256
              Relay_Log_Space: 107
              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
1 row in set (0.00 sec)

--啟用Slave的應(yīng)用日志服務(wù)
START SLAVE語句會啟動兩個線程。I/O線程會從Master服務(wù)器讀取事件并將它們存放到relay log中。SQL線程會從relay log中讀取事件并執(zhí)行它們。執(zhí)行START SLAVE需要SUPER權(quán)限。

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

--Slave日志中的內(nèi)容
[root@localhost data]# tailf /log/err.log
160427  5:57:08 [Note] 'CHANGE MASTER TO executed'. Previous state master_host='', master_port='3306', master_log_file='', master_log_pos='4'. New state master_host='192.168.78.139',
master_port='3306', master_log_file='mysql-bin.000010', master_log_pos='107'.
160427  5:57:23 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000010' at position 107, relay log '/log/binlog/mysqld-relay-bin.000001' position: 4
160427  5:57:25 [Note] Slave I/O thread: connected to master 'repl@192.168.78.139:3306',replication started in log 'mysql-bin.000010' at position 107

以上是“MySQL 5.5 復(fù)制搭建的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

分享題目:MySQL5.5復(fù)制搭建的示例分析-創(chuàng)新互聯(lián)
本文鏈接:http://muchs.cn/article42/dpjdhc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)站內(nèi)鏈靜態(tài)網(wǎng)站、微信公眾號自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站