windows下安裝mysql5.6.13的主從複製

來源:互聯網
上載者:User

標籤:

如下操作均在vmware 虛擬機器中winows xp 測試成功

中間走了很多彎路,網上的很多資料都是針對5.1以前的版本,在新版中根本無法使用,所以根據自己的實踐整理了這篇文章

主服務:192.168.131.21

從伺服器:192.168.131.22

1、主機的配置

my.ini中配置:

server-id = 1 

binlog_format = "ROW"

log-bin=mysql-bin

啟動服務後進入mysql命令列執行如下操作

GRANT ALL ON *.* TO ‘slave1‘@‘192.168.131.22‘  IDENTIFIED BY ‘123456‘;

如果需要進行某個資料庫的同步的話,最好只建立對應資料庫的許可權,如:

GRANT ALL ON test1.* TO ‘slave1‘@‘192.168.131.22‘  IDENTIFIED BY ‘123456‘;

這樣只會同步該資料庫的內容。

2、從伺服器設定

my.ini:

server-id = 2

relay-log-purge=1

skip-slave-start 

replicate-ignore-db=mysql #此處為不同步mysql資料庫的內容此處如果為多資料庫的話中間以逗號分開

然後啟動mysql 進入命令列 執行如下命令

CHANGE MASTER TO MASTER_HOST=‘192.168.131.21‘, MASTER_USER=‘slave1‘,  MASTER_PASSWORD=‘123456‘;

3、啟動主從複製

首先啟動主伺服器的服務

其次啟動從伺服器的服務

然後在從伺服器命令列執行

start slave;

然後執行如下命令 查看從伺服器狀態

SHOW SLAVE STATUS\G

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.131.21
                  Master_User: slave1
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000007
          Read_Master_Log_Pos: 120
               Relay_Log_File: rainpetlab2-relay-bin.000010
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000007
             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: 120
              Relay_Log_Space: 625
              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
                  Master_UUID: 2ab70a0e-a1c4-11e2-9c60-60eb69d711ca
             Master_Info_File: D:\wamp\data5\master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the sla
ve I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

註:Slave_IO_Running: Yes
            Slave_SQL_Running: Yes必須為yes才行

還要注意的是:

我在做從伺服器時,是停止服務,然後整體複製的data目錄,如果不進行任何修改的話,會出現如下提示:


 [ERROR] Slave I/O: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work. Error_code: 1593
121122 17:40:58 [Note] Slave I/O thread exiting, read up to log ‘FIRST‘, position 4

這個時候,應該刪除data目錄下的auto.cnf,然後重啟服務

執行 start slave;即可

之後在主伺服器上建立資料庫

再從伺服器上就可看到同步過來的資料了


 還有如果更改從伺服器的機器名的話 可這樣這樣執行命令:

stop slave;

reset slave;

start slave;

windows下安裝mysql5.6.13的主從複製

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.