Mysql 主從伺服器資料同步

來源:互聯網
上載者:User

標籤:

  1. 安裝2台windows Server 伺服器,分別安裝Mysql,配置環境變數,完成安裝確認在CMD視窗可以使用Mysql命令
  2. 在Master伺服器上建立同步帳號,確保Slave伺服器能訪問Master伺服器資料庫
    Master DB Server IP:10.10.0.144
    Slave DB Server IP:10.10.0.145
    Mysql > grant replication slave on *.* to [email protected] identified by ‘Password‘;
    Mysql > flush privileges;
  3. 進入Slave伺服器,測試能否成功訪問Master伺服器
    Mysql > mysql -ubackup -p -h10.10.0.144
  4. 回到Master伺服器,修改Mysql設定檔,開啟:C:\ProgramData\MySQL\MySQL Server 5.6\My.ini
    添加或修改如下內容:
    #設定資料庫標識
    server_id=1
    #任何一個事務提交之後就立即寫入到磁碟中的二進位檔案
    sync_binlog=1
    #保持資料一致性,建議配置
    innodb_flush_log_at_trx_commit=1
    #開啟伺服器二進位日誌
    log-bin=mysql-bin
    #設定log格式
    binlog_format=MIXED
    #忽略不同步的資料庫test,這個可以不用寫
    binlog-ignore-db=test  
  5. 重啟Master伺服器資料庫,檢查二進位日誌是否開啟
    Mysql > show variables like ‘%bin‘;
    Mysql > show master status;
    鎖定所有執行:
    Mysql > flush tables with read lock;
    Mysql > unlock tables;
  6. 回到Slave伺服器,修改設定檔C:\ProgramData\MySQL\MySQL Server 5.6\My.ini
    server-id=2
    #忽略不同步的某張表
    replicate-ignore-table=db.name.TableName
    replicate-ignore-db=db.name
  7. 重啟Slave伺服器的資料庫服務
    停止Slave服務
    Mysql > stop slave;
    設定Slave伺服器與Master伺服器資料同步
    Mysql > change master to master_host=‘10.10.0.144‘,master_user=‘backup‘,master_password=‘password‘,master_log_file=‘binary-log.000001‘,master_log_pos=120;
    查看狀態
    Mysql > show slave status\G
    Mysql > start slave;
    再次查看狀態
    Mysql > show slave status\G
    出現
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes
    即配置成功。
  8. 注意:將Slave伺服器的IP地址添加到Master伺服器3306連接埠白名單

Mysql 主從伺服器資料同步

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.