MySQL主從同步基本配置

來源:互聯網
上載者:User

標籤:roo   pre   set   star   res   mct   cto   ast   pos   

準備:兩台MySQL資料庫

一、配置主要資料庫

1、添加使用者

mysql> grant replication slave on *.* \

    -> to 

    -> [email protected]"192.168.4.12"                        授權使用者/ip

    -> identified by "111111";                                密碼


2、啟動binlog日誌

[mysqld]

server_id=1

log-bin=master1

binlog_format="mixed"


3、重起資料庫服務

[[email protected] ~]#systemctl restart mysqld


4 查看日誌資訊  

mysql> show  master  status;


二、配置從資料庫

1、驗證主庫提供的授權使用者

    [[email protected] ~]# mysql -h192.168.4.11 -uslaveuser -p111111

    

2、修改設定檔 指定設定檔

    [mysqld]

    server_id=2

    log-bin=master2

 

3、指定主庫資訊  

    mysql> change master to master_host="192.168.4.11",

    master_user="slaveuser",

    master_password="111111",

    master_log_file="master1.000001",

    master_log_pos=154;

    

4、開啟服務

        mysql> start slave;


     關閉服務

        mysql> stop slave;

     刪除服務

        mysql> reset slave;

        

5、查看

    mysql> show slave status\G;

    

    Slave_IO_Running: Yes        IO線程已運行

    Slave_SQL_Running: YesSQL線程已運行

    

從資料庫目錄下多的檔案

 [[email protected] ~]#cat /var/lib/mysql/*

        master.info                串連主伺服器資訊

        relay-log.info                  中斷日誌資訊

        主機名稱-relay-bin.xxxxxx        中斷日誌

        bogon-realy-bin.index                中斷日誌索引檔案

        

  三、測試主從同步配置

     1、 主伺服器上建立庫

    mysql> create database ctoll;

     2、 從伺服器也能查看

    

【一主多從】

    mysql> grant replication slave on *.*  

    to

    [email protected]"%"                                            % --->多台主機

    identified by "111111";

    

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.