mysql8 主从库搭建
备份
/usr/bin/xtrabackup --defaults-file=/etc/my.cnf --no-server-version-check --user=bk --password=ocm123 --backup --target-dir=/data/bk/bk_`date +%Y%m%d%s`
恢复
/usr/bin/xtrabackup --prepare --target-dir=/data/bk/bk_202408021722560617
/usr/bin/xtrabackup --copy-back --target-dir=/data/bk/bk_202408021722560617
主库创建复制用户
create user 'repl1'@'%' identified by 'repl1ADF2020qwer';
GRANT replication slave ON *.* to repl1@'%' ;
flush privileges;
同步复制
change master to master_host='100.162.100.150', master_user='repl1', master_password='ocm123', MASTER_PORT=3308,master_log_file='binlog.007930',MASTER_LOG_POS=277;
mysql> start slave;
ERROR 1872 (HY000): Replica failed to initialize applier metadata structure from the repository
解决1872
从数据库可能以前配置过,生成过中继日志文件,导致从数据库 slave 中还记录着旧数据,需要reset
reset slave
start slave