search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[MySQL] MySQL replication 設定步驟

1.設置master 的 my.cnf

server-id = 501
#
主要伺服器ID,隨你喜歡數字,但與slave不能相同

log_bin = /var/log/mysql/mysql-bin.log
#binlog
放置的路徑

expire_logs_days = 10
#binlog
要存放的天數,過期就會刪掉

max_binlog_size = 100M
#binlog
每一個檔案大小,達到就會切檔

binlog-do-db=dbname
#
計畫備份的資料庫,不設置的話備份binlog-ignore-db以外所有資料庫,包括創建資料庫  

binlog-ignore-db=mysql,test,information_schema
#
忽略備份的資料庫

2.添加複製使用者repluser,密碼passwd,授權該使用者可複製許可權

mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repluser'@'slaveip' IDENTIFIED BY 'passwd';

mysql>FLUSH PRIVILEGES;

 

3.設置slave 的 my.cnf

server-id  = 502

master-host     =  masterip

master-user     =   repluser

master-password =   passwd

master-port     =  3306

log-bin=mysql-bin

master-connect-retry=60

replicate-do-db=dbname

log-slave-updates

read-only=1#可設定唯讀

 

4.主要伺服器鎖表

mysql> FLUSH TABLES WITH READ LOCK;

注意,鎖定後資料庫唯讀,因此最好在資料庫非訪問期間做此操作

 

5.master匯出資料庫

mysqldump -uroot -ppasswd dbname>dbname.sql

 

6.slave匯入資料庫

mysql -uroot -ppasswd dbname< dbname.sql

 

 

7.查看並記錄master狀態

mysql> show master status;

*************************** 1. row ***************************           File: mysql-bin.000026
Position: 56790952
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

記下File和Position

 

8.slave設置複製點

mysql > stop slave;

mysql > change master to master_host='masterip', master_user='repluser', master_password='passwd', master_log_file=' mysql-bin.000026', master_log_pos=56790952;

mysql > start slave;

 

9.檢查slave狀態

mysql >show slave status\G;

Slave_IO_Running和Slave_SQL_Running均為Yes說明配置成功。

 

10.解除master鎖表

mysql >unlock tables;



熱門推薦

本文由 charleslin74pixnetnetblog 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦