- 主库备份数据,拷贝至从节点
1.1 备份数据
sudo python /data/apps/xtrabackup/script/xtrabackup.py -m full
备份目录为:
/data/mysql_bakcup/<port>/<date>/full_<date>
例:/data/mysql_backup/13306/20231124/full_164044/
1.2 拷贝备份数据至从节点
scp -r /data/mysql_bakcup/<port>/<date>/full_<date> /data/
例:scp -r /data/mysql_backup/13306/20231124/full_164044/ kde-offline2:/data/
- 停止从库服务,备份从库数据目录
- 停止从库服务
systemctl stop mysql13306 #注意,服务名称端口根据实际情况进行修改
- 备份数据目录,重新创建数据目录
mv /data/mysql13306/ /data/mysql13306_bak20231124/
mkdir /data/mysql13306/
- 将从库mysql数据拷贝至从库数据目录
cp -r /data/full_164044/* /data/mysql13306/
cp /data/mysql13306_bak20231124/my13306.cnf /data/mysql13306/ #覆盖
chown -R mysql:mysql /data/mysql13306/
- 查看从库节点的binlog信息中gtid,并记录
head -1 /data/mysql13306/xtrabackup_binlog_info
mysql-bin.000009 387167570 7a2ffba6-7ab8-11ee-815f-fa163e25443d:1-2139088
记录:7a2ffba6-7ab8-11ee-815f-fa163e25443d:1-2139088
- 启动从库数据库
systemctl start mysql13306
- 登录从库进行配置
mysql -h127.0.0.1 -P13306 -uroot -pKingsoft_com123!
reset master;
set global gtid_purged="7a2ffba6-7ab8-11ee-815f-fa163e25443d:1-2139088";
change master to master_host='10.5.x.x',master_port=13306,master_user='replica',master_password='Kingsoft_com123!',MASTER_AUTO_POSITION=1;start slave;
查看从库状态
show slave status\G;