場景
整個庫的數(shù)據(jù)量非常大得哆,使用dump備份時間很久馋评;主庫可以暫停寫入一段時間,故采用rsync同步數(shù)據(jù)制作主從的方式
- 主庫已經(jīng)有同步需要的賬號
- 停止從庫,刪除從庫下的數(shù)據(jù)
systemctl stop mysqld.service
rm -rf /home/mysql/*
- 主庫全量rsync同步數(shù)據(jù)到從庫(開啟screen其爵,時間比較久):
screen -R rsync
rsync -avz /home/mysql/ mysql@10.201.2.183::mysql --password-file=/etc/rsync.pas
- 設(shè)置主庫mysql只讀
show global variables like "%read_only%";
set global read_only=1;
set global super_read_only=1;
flush tables with read lock;
flush privileges;
查看主庫的信息(確保postion不變)
show master status;
mysql-bin.xxx | xxxxx
- 主庫再rsync數(shù)據(jù)到從庫
rsync -avz /home/mysql/ mysql@10.201.2.183::mysql --password-file=/etc/rsync.pas
- 同步完數(shù)據(jù)剔宪,放開主庫的寫
unlock tables;
set global read_only=0;
set global super_read_only=0;
show global variables like "%read_only%";
#read_only | OFF
flush privileges;
- 從庫刪除uuid信息嘿悬,啟動從庫齿兔,制作主從關(guān)系
登錄從庫:
rm -rf /home/mysql/auto.cnf
systemctl start mysqld.service
登錄mysql:
CHANGE MASTER TO
MASTER_HOST='10.201.2.183',
MASTER_USER='repl',
MASTER_PASSWORD='xxxx',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.xxxx',
MASTER_LOG_POS=xxxx,
MASTER_CONNECT_RETRY=10;
start slave;
show slave status\G;