MySQL資料庫配置主從同步

來源:互聯網
上載者:User

MySQL資料庫配置主從同步

1.環境說明:DB master: 172.16.1.55
            DB slave: 172.16.1.56
2.Server-id 配置(/etc/my.cnf):
主庫配置server-id要比從庫的ID小。
主庫ID設定:Server-id=55
從庫ID設定:Server-id=56
3.日誌格式設定(/etc/my.cnf):
log-bin=mysql-bin (主庫、從庫都設定)
4.主庫授權從庫的使用權限設定:
grant replication slave on *.* to ‘slave’@’172.16.1.56’ identified by ‘P@ssw0rdskycloud’;
flush privileges;
5.主庫設定要進行主從同步的資料庫和不需要主從同步的資料庫:
使用binlog-do-db=XXX手動指定需要同步的資料庫;
使用binlog-ignore-db=XXX手動指定不需要同步的資料庫;
vi /etc/my.cnf:
[mysqld]
log-bin=mysql-bin
server-id= 55
binlog-do-db = test
binlog-do-db = information_schema
binlog-do-db = performance_schema
binlog-ignore-db = mysql
6.從庫設定要從主庫同步的資料庫和不需要從主庫同步的資料庫:
使用replicate-do-db=XXX手動指定需要同步的資料庫;
使用replicate-ignore-db=XXX手動指定不需要同步的資料庫;
vi /etc/my.cnf:
[mysqld]
log-bin=mysql-bin
server-id= 56
replicate-do-db = test
replicate-do-db = information_schema
replicate-do-db = performance_schema
replicate-ignore-db = mysql
7.主庫和從庫分別重啟mysql資料庫。
service mysql restart
8.主庫上執行:
show master status;
記錄下mysql-bin的檔案和位置。
比如看到的位置是:mysql-bin.000014  107
9.從庫上先停止slave狀態:
slave stop;
10.從庫上手動執行資料同步:
change master to  master_host=’172.16.1.55’,master_user=’slave’,master_password=’P@ssw0rdskycloud’,master_log_file=’mysql-bin.000014’,master_log_pos=107;
11.開啟從庫的slave機制:
slave start;
12.查看slave slave status\G;

13.測試mysql 主從狀態:
在主庫上建立表,然後到從庫上使用相對應的資料庫執行show tables;語句。
在主庫資料表中插入資料,然後從從庫中執行select查詢語句,查看同步過來的資料表中的資料記錄。
create table linxi (id int not null primary key,name char(20));
insert into linxi values (1,’lutaoxu’);
從庫上執行查詢語句:
use test;
select * from linxi;

--------------------------------------分割線 --------------------------------------

MySQL主從同步設定的重要參數log_slave_updates 

Ubuntu 14.04下安裝MySQL

《MySQL權威指南(原書第2版)》清晰中文掃描版 PDF

Ubuntu下Nginx做負載實現高效能WEB伺服器5---MySQL主主同步

生產環境MySQL主主同步主鍵衝突處理

MySQL主從失敗 錯誤Got fatal error 1236

MySQL主從複製,單台伺服器上實施

本文永久更新連結地址:

相關文章

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.