mysql主從復(fù)制的步驟

這篇文章主要講解了“MySQL主從復(fù)制的步驟”,文中的講解內(nèi)容簡單清晰,易于學(xué)習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習“mysql主從復(fù)制的步驟”吧!

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

 一、環(huán)境描述
服務(wù)器ip:192.168.0.2
從數(shù)據(jù)庫服務(wù)器ip:192.168.0.3
主從服務(wù)器上的已全新安裝,但并為投入生產(chǎn),所以無數(shù)據(jù)產(chǎn)生。
二、主從復(fù)制配置
 1.主數(shù)據(jù)庫服務(wù)器master配置
  (1)為從服務(wù)器slave授權(quán)
   mysql> grant replication slave on *.* to  identified by "123";
   (2)查看master狀態(tài)
   mysql> show master status;
 +------------------+----------+--------------+------------------+
 | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 +------------------+----------+--------------+------------------+
 | mysql-bin.000003 |      400 |              |                  |
 +------------------+----------+--------------+------------------+
 1 row in set (0.00 sec)
 記下file和position,一會配置slave會用到。(file為mysql日志的文件,position為日志的線索號,從服務(wù)器將從這么位置開始復(fù)制) 
 2.從數(shù)據(jù)庫服務(wù)器slave配置
  (1)修改slave的server id,避免和其他my的重復(fù)
   vi /etc/my.cnf
   server-id = 2
   (2)執(zhí)行sql語句的同步
   mysql> change master to master_host=192.168.0.2, master_user=slave, master_password=123, master_log_file=mysql-bin.000003, master_log_pos=400;
   (3)啟動slave的同步功能
   mysql> start slave;
    (4)查看slave狀態(tài)
mysql> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.2
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 548
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 399
        Relay_Master_Log_File: mysql-bin.000003
             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: 548
              Relay_Log_Space: 554
              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:
1 row in set (0.02 sec)
 
ERROR:
No query specified
        注:Slave_IO_Running: Yes
            Slave_SQL_Running: Yes當IO和SQL這兩個進程都是Yes,master和slave就可以進行主從復(fù)制了。
三、驗證測試
 1.在master上創(chuàng)建一個測試表(root用戶)
 mysql> use test
 mysql> create table tbs (id int);
 mysql> insert into tbs values(1);
 2.在slave上查看是否復(fù)制成功(root用戶)
 mysql> use test
 mysql> show tables;
 
 mysql> select * from tbs;
                 +------+
                 | id   |
                 +------+
                 |    1 |
                 +------+
               1 row in set (0.00 sec)
顯示復(fù)制成功!

感謝各位的閱讀,以上就是“mysql主從復(fù)制的步驟”的內(nèi)容了,經(jīng)過本文的學(xué)習后,相信大家對mysql主從復(fù)制的步驟這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

新聞名稱:mysql主從復(fù)制的步驟
標題路徑:http://muchs.cn/article8/gdejip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、標簽優(yōu)化、品牌網(wǎng)站制作、企業(yè)建站

廣告

聲明:本網(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ù)器托管