1、首先部署mysql主服务:
详见上一篇《ubuntu22.04部署mysql---单机》
https://blog.51cto.com/u_14175560/6766135
上述部署好后,主节点server_id:
vim /etc/mysql/my.cnf
##新增配置:
[mysqld]
server_id = 1
重启mysql:
systemctl restart mysql
登录mysql,指定从节点IP,运行下述(注意修改对应从节点IP)
mysql -uroot -p
mysql> create user repl@'从节点IP' identified by 'Repl@2020';
mysql> grant REPLICATION CLIENT,REPLICATION SLAVE ,SELECT ON *.* to repl@'从节点IP';
2、部署从节点
详见上一篇《ubuntu22.04部署mysql---单机》
https://blog.51cto.com/u_14175560/6766135
上述部署好,指定从节点server_id:
##配置my.cnf,指定server_id:
vim /etc/mysql/my.cnf
##新增配置:
[mysqld]
#MySQL Server layer basic setting
server_id = 5 ##注意和master节点区分开
然后重启mysql
systemctl restart mysql
登录数据库,指定master节点IP,启动slave
mysql> CHANGE MASTER TO MASTER_HOST='master节点IP',master_user='repl',master_password='Repl@2020',master_auto_position=1;
mysql> start slave;
上述运行报错:
因,GLOBAL.GTID_MODE = OFF故无法配置,修改GTID_MODE状态: ---注意,修改GTID_MODE状态需要主从节点同时修改
注意:GTID_MODE状态修改有固定顺序,不能跨序修改,顺序如下:
OFF <-> OFF_PERMISSIVE <-> ON_PERMISSIVE <-> ON
###查看GTID_MODE状态:
show global variables like 'gtid_mode';
###修改GTID_MODE状态(主从节点都修改):
set @@GLOBAL.GTID_MODE=OFF_PERMISSIVE;
set @@GLOBAL.GTID_MODE=ON_PERMISSIVE;
##改成上述ON_PERMISSIVE 状态就OK
上述修改后,重新运行
mysql> CHANGE MASTER TO MASTER_HOST='master节点IP',master_user='repl',master_password='Repl@2020',master_auto_position=1;
mysql> start slave;
配置成功