MYSQL 主主同步记录
[root@mongo03~]# grep password /var/log/mysqld.log |grep generated
2021-07-02T03:32:30.820928Z 1 [Note] A temporary password is generated for root@localhost: 9:pzrp!eaa
mysql -uroot –p9:pzrp!ea #该操作为本地登陆mysql服务端,实际密码是随机生成的,密码都不一样。
- 然后在mysql 命令行中,执行以下sql,则先需要登陆到对应的mysql命令行中,执行相关命令。
alter user root@'localhost' identified by 'test_mysqlABC';
create user 'root'@'%' IDENTIFIED by 'ccodqnsoft4.9';
grant all privileges on *.* to 'root'@'%';
create user 'rep'@'%' IDENTIFIED by '2EbQ605eYGxE1h4k';
grant replication slave,replication client on *.* to 'rep'@'%';
flush privileges;
- 在两台mysql中都执行,先执行,则先需要登陆到对应的mysql命令行中,执行相关命令。
A服务器上执行: stop slave;
B服务器上执行: stop slave;
A服务器上执行: show master status \G; #查看File 和Position字段
B服务器上执行: show master status \G; #查看File 和Position字段
- 然后对应修改修改
master_log_file
和,master_log_pos
字段,注意ip别添加反了。则先需要登陆到对应的mysql命令行中,执行相关命令。
change master to master_host='10.1.2.87',master_user='ucds',master_password='ucds',master_log_file='mysql-bin.000001',master_log_pos=923;`
change master to master_host='10.1.2.86',master_user='ucds',master_password='ucds',master_log_file='mysql-bin.000001',master_log_pos=923;
- 然后在A和B服务器上面登陆mysql 执行启动
start slave
命令
start slave;
Last_IO_Error: Error connecting to source 'rep@10.1.2.86:3306'. This was attempt 1/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
执行如下更换身份验证插件
ALTER USER 'rep'@'%' IDENTIFIED WITH mysql_native_password BY 'ccodqnsoft4.9'; FLUSH PRIVILEGES;
- 然后执行两台A和B服务器上执行
show slave status \G;
命令 查询都yes,则说明mysql主主也做好了。
show slave status \G; #执行该命令
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
评论区