mysql8主从配置
1、在所有主从上执行,因为每个机器都有可能使master:
2、修改所有主从的配置文件my.cnf:
3、重启这三台机器,分别执行:
4、进入slave01的mysql命令行,执行:
5、遇到的问题总结:
1、在所有主从上执行,因为每个机器都有可能使master:
# mysql -u root -p -h 127.0.0.1
use mysql;
create user 'repl'@'%' identified with mysql_native_password by 'pass456';
#ALTER user 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'pass456';
select User,authentication_string,Host,plugin from user;
flush privileges;
grant replication slave on *.* to 'repl'@'%';
flush privileges;
2、修改所有主从的配置文件my.cnf:
[mysqld]
#server_id不可以相同,可以改成ip对应
server_id=161
log-bin=/data1/mysql8/data/mysql-bin
relay_log=relay_bin
log_slave_updates=on
#开启gtid模式
gtid_mode=ON
enforce_gtid_consistency=ON
3、重启这三台机器,分别执行:
systemctl stop mysql8d.service
systemctl start mysql8d.service
systemctl status mysql8d.service
在主库上查询
# mysql -u root -p -h 127.0.0.1
show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 1292
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 289a66de-8ae3-11ec-8b6e-000c296bacc6:1-9
1 row in set (0.00 sec)
4、进入slave01的mysql命令行,执行:
# mysql -u root -p -h 127.0.0.1
stop slave;
change master to master_host='192.168.100.161', master_port=3306, master_user='repl', master_password='pass456',master_auto_position=1;
change master to master_host='192.168.100.161', master_port=3306, master_user='repl', master_password='pass456',master_auto_position=0;
change master to master_host='192.168.100.161', master_port=3306, master_user='repl', master_password='pass456', master_log_file='mysql-bin.000001',master_log_pos=1292;
start slave;
#查看是否主从成功
show slave status\G
#结果显示两个yes表示成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
进入slave2,操作同上,一模一样。
如果报错了要重新设置master信息
需要现在从库停止slave;
mysql> stop slave;
mysql> RESET MASTER ALL;
如果报这个错
ERROR 1776 (HY000): Parameters MASTER_LOG_FILE, MASTER_LOG_POS, RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION is active.
就执行这个
mysql> change master to master_auto_position=0;
##5、遇到的问题总结: 以下内容为复制,没有经过自己验证
问题1:ERROR 1777 (HY000): CHANGE MASTER TO MASTER_AUTO_POSITION = 1 cannot be executed because @@GLOBAL.GTID_MODE = OFF
解决:
1.在所有主从实例结构中执行:
set global ENFORCE_GTID_CONSISTENCY = WARN;
##说明,这是一个警告模式,如果有还没有执行完的sql
2.如果没有警告,所有实例中执行:
set global ENFORCE_GTID_CONSISTENCY = ON;
3.在所有实例中执行:
set global GTID_MODE = OFF_PERMISSIVE;
4.在所有实例中执行:
set global GTID_MODE = ON_PERMISSIVE;
5,在所有主从实例中执行,检查是否还有事务没有结束:
SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';
#注意value一定要为0
6.检查slave的binlog点位,如果还没有应用完binlog,则需等待
show slave status\G;
7.在所有实例中执行:
set global GTID_MODE = ON;
8.在从库上执行:
stop slave;
CHANGE MASTER TO MASTER_AUTO_POSITION = 1;
start slave;
已经升级为GTID模式了。
最后记得更改my.cnf文件:
gtid_mode = on
enforce_gtid_consistency = on
问题2:[root@CT-DevOps-DB sysadm]# mysql -u root -p bash: mysql: command not found…
解决:
添加软链接
ln -s /usr/local/mysql8/bin/mysql /usr/bin
文章参考:
原文链接:https://blog.csdn.net/qq_15350581/article/details/114090794
网友评论