1. 程式人生 > >mysql增加從庫

mysql增加從庫

1、將主庫前一天備份的資料傳輸到從庫機上。

主庫備份語句加上--master-data=2,記錄其change master to資訊。

2、在從庫上匯入主庫備份資料。

mysql -uroot -ppasswd < bak_20180411.sql

3、檢視從庫上的備份資料:bak_20180411.sql,找到其中的CHANGE MASTER TO欄位,記錄position。

    cat bak_20180411.sql | awk 'NR==22{print}'

4、主庫與從庫建立複製賬號:

grant REPLICATION SLAVE,replication client on *.* to 'root'@'%' identified by '123456';

5、將從庫定位到主庫(用到了備份資料中的CHANGE MASTER TO資訊):

change master to master_user='root',master_host='192.168.18.1',master_password='123456',master_log_file='mysql-bin.00005',master_log_pos=84011;

6、啟動從庫:

start slave;

7、檢視主從是否成功:

show slave status\G;

檢視Last_IO_Error是否有報錯。根據錯誤提示修改檢查。

Slave_IO_Running         Slave_SQL_Running      Seconds_Behind_Master  檢視三個欄位。