前言:我这里使用的一台机器安装了多个mysql实例
https://www.csdcb.cn/article/276.html
第一步:配置主机A 3308
1.1、编辑my.cnf
vim /opt/extdata/mysql/3308/my.cnf
server-id=3308
log-bin=/opt/extdata/mysql/3308/mysql-bin.log
auto_increment_increment=2
auto_increment_offset=2
relay_log=/opt/extdata/mysql/3308/mysql-relay-bin.log
log_slave_updates = 1
default_authentication_plugin=mysql_native_password
1.2、登陆添加复制用户
mysql -u root -P 3308 -proot -S /opt/extdata/mysql/3308/mysql.sock
create user 'repl'@'%' identified by 'reple_password';
grant replication slave on *.* to 'repl'@'192.168.200.144';
1.2.1、使用 mysql_native_password 修改用户密码
alter user 'repl'@'%' IDENTIFIED with mysql_native_password by 'reple_password';
1.2.2、使用创建用户尝试登陆
mysql -h192.168.200.144 -u repl -P 3308 -preple_password -S /opt/extdata/mysql/3308/mysql.sock
mysql -u repl -P 3308 -preple_password -S /opt/extdata/mysql/3308/mysql.sock
1.2.3、查看主节点日志文件和状态
show master status;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000012 | 156 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
File 对应 master_log_file
Position 对应 master_log_pos
1.3、配置复制信息
change master to
master_host='192.168.200.144',
master_port=3309,
master_user='repl',
master_password='reple_password',
master_log_file='mysql-bin.000011',
master_log_pos=156 ;
3.4、启动slave
stop slave;
start slave;
show slave status\G;
3.5、查看 slave 状态
show slave status\G;
第二步:配置主机B 3309
2.1、编辑 my.cnf
vim /opt/extdata/mysql/3309/my.cnf
log-bin=/opt/extdata/mysql/3309/mysql-bin.log
auto_increment_increment=2
auto_increment_offset=1
relay_log=/opt/extdata/mysql/3309/mysql-relay-bin.log
log_slave_updates = 1
default_authentication_plugin=mysql_native_password
2.2、登陆添加复制用户
mysql -u root -P 3309 -proot -S /opt/extdata/mysql/3309/mysql.sock
create user 'repl'@'192.168.200.144' identified by 'reple_password';
grant replication slave on *.* to 'repl'@'%';
2.2.1、使用 mysql_native_password 修改用户密码
alter user 'repl'@'%' IDENTIFIED with mysql_native_password by 'reple_password';
2.2.2、使用创建用户尝试登陆
mysql -h192.168.200.144 -u repl -P 3309 -preple_password -S /opt/extdata/mysql/3309/mysql.sock
2.2.3、查看主节点日志文件和状态
show master status;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000011 | 156 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
File 对应 master_log_file
Position 对应 master_log_pos
2.3、配置复制信息
change master to
master_host='192.168.200.144',
master_port=3308,
master_user='repl',
master_password='reple_password',
master_log_file='mysql-bin.000012',
master_log_pos=156;
2.4、启动slave
stop slave;
start slave;
2.5、查看 slave 状态
show slave status\G;
第三步:修改用户可远程登录
use mysql;
select user,host from user;
alter user 'repl'@'%' IDENTIFIED with caching_sha2_password by 'reple_password';
alter user 'repl'@'%' IDENTIFIED with mysql_native_password by 'reple_password';
FLUSH PRIVILEGES;

