MySQL 主從複製配置

來源:互聯網
上載者:User

標籤:

1 . 安裝MySQL server

 2 . 修改master配置在master機器上的 /etc/my.cnf中添加如下幾個參數
[mysqld]
innodb_buffer_pool_size=6g
innodb_log_file_size=1g
max_connections=4096
skip-name-resolvelog-bin=mysql-binserver-id=1

3 .修改slave配置
在slave機器上的 /etc/my.cnf中添加如下幾個參數
[mysqld]
innodb_buffer_pool_size=6g
innodb_log_file_size=1g
max_connections=4096
skip-name-resolvelog-bin=mysql-bin
server-id=2

4. 在master上建立複製使用者
A)登入mysql
mysql -uroot
B)執行如下命令
CREATE USER ‘repl‘@‘%‘ IDENTIFIED BY ‘slavepass‘;
GRANT REPLICATION SLAVE ON *.* TO ‘repl‘@‘%‘;


5. 查看master的binlog位置
A)登入mysql
B)執行如下命令
show master status\G
輸出如下:

+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000003 | 73       | test         |                  |+------------------+----------+--------------+------------------+

6. 確保此時master和slave的資料一致。
如果不一致,先把slave的資料清除掉,然後用mysqldump命令重新匯入master的資料

7.把slave指向master
A)登入slave上的mysql
B) 執行如下命令
change master to master_host=‘<IP>‘, master_log_file=‘mysql-bin.000003‘ , master_log_pos=73, master_user=‘repl‘, master_password=‘slavepass‘;
start slave;
 
至此,主從搭配完成。

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.