上次遇到了一个主从复制错误1782,解决办法:https://www.cnblogs.com/102x/p/10984473.html
1.搭建具有mysql备份恢复工具percona-xtrabackup的MySQL容器:方法:https://blog.csdn.net/qq_39122146/article/details/107989249
2.rds上创建一个普通账户,无需分配任何库的权限,用于从库同步使用;
3.添加ecs实例IP至RDS白名单;
4、下载RDS的全量备份至ECS实例,全量备份坐标见下图;
下载好的文件为:hins11787893_data_20200814034712.tar
1、添加下述参数至mysql配置文件的[mysqld]标签下;
server-id = 2156239584
log-bin=mysql-bin
relay-log=relay-bin
gtid_mode=on
enforce_gtid_consistency=on
binlog_format=row
# 并行复制配置
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16
master_info_repository=TABLE
2.解压数据库备份文件:
sudo tar -xvf hins11787893_data_20200814034712.tar
3.将备份文件hins11787893_data_20200814034712.tar移走:
sudo mv hins11787893_data_20200814034712.tar /qj/data/
4.进入MySQL容器进行备份
备份准备:
xtrabackup --prepare --target-dir=/data/backup -S /var/run/mysqld/mysqld.sock -H 127.0.0.1 -uroot -p123456 -P3306
进行备份:
xtrabackup --copy-back --target-dir=/data/backup -S /var/run/mysqld/mysqld.sock -H 127.0.0.1 -uroot -p123456 -P3306
rm -rf /var/lib/mysql/*
5.修改mysql配置文件为跳过授权,即添加下述配置至[mysqld]标签下
skip-grant-tables
use mysql;
truncate slave_gtid_info;
truncate slave_master_info;
truncate slave_relay_log_info;
truncate slave_worker_info;
select host,user from mysql.user;
update mysql.user set authentication_string=password('新密码') where user='aliyun_root';
这时会报错,Unknown system variable ‘maintain_user_list’,如图:
表示有触发器.
注意: 在mysql5.7 中, aliyun_root 才是真正超级权限账号.
1.查看并删除触发器.命令如下:
select trigger_schema,trigger_name from information_schema.triggers;
删除这两个触发器,命令如下:
drop trigger sys.sys_config_insert_set_user;
drop trigger sys.sys_config_update_set_user;
find /var/lib/mysql/ -iname *.trg
直接把查询的内容删除就可以
重新修改root和aliyun_root账号的密码
update mysql.user set authentication_string = password('新的密码') where user='用户名' and host='%';
flush privileges;
注释或删除MySQL的跳过授权配置:
skip-grant-tables
再次登录mysql数据库时请指定-h 127.0.0.1
mysql -u root -p -h127.0.0.1
reset slave;
change master to master_host='rm-xxxxxxxx.mysql.rds.aliyuncs.com',master_port=3306,master_user='xxxxxxxx',master_password='xxxxxxxx',master_auto_position=0;
主库的二进制文件名及当前备份的position编号记录在/data/tmp/xtrabackup_slave_filename_info,如下图
复制下述语句时注意去除MATSER_LOG_POS后面值两边的单引号
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000627', MASTER_LOG_POS=461950385;
start slave;
show slave status\G;
确认Slave_IO_Running、Slave_SQL_Running的值均为Yes即可,如下图所示
参考:https://segmentfault.com/a/1190000018516873
http://www.itzoo.net/db/997.html
https://blog.csdn.net/cyfblog/article/details/101017375
https://yq.aliyun.com/articles/688509