书接上回,通过Linux 环境搭建 MySQL8.0.28 主从同步环境,在同一台机器上通过不同的端口来区分实例,搭建 MySQL 三节点的一主两从架构的测试环境。由于搭建环境时的用户密码过于简单,安全扫描出来弱口令,需要整改,则当时就使用如下命令修改了 root 和 rep 用户的密码。
alter user root@'%' identified by 'MySQL8.0';
alter user rep@'%' identified by 'MySQL8.0';
select User,Host,plugin ,max_user_connections,max_connections from mysql.user;
修改完密码后,MySQL 实例一直没有重启,复制也是正常的,直到这个月初的机房断电主机关机,MySQL 实例重新启动后,主从复制出现了中断。
nohup mysqld_safe --defaults-file=/mysql/conf/my3306.cnf --user=mysql &
nohup mysqld_safe --defaults-file=/mysql/conf/my3307.cnf --user=mysql &
nohup mysqld_safe --defaults-file=/mysql/conf/my3308.cnf --user=mysql &
发现问题
登录到从节点查看从库复制状态,发现“MY-001045”错误。
mysql -h192.168.77.86 -uroot -pMySQL8.0 -P 3308 -S /mysql/data/mysql3308/socket/mysql3308.sock
show slave statusG
show replica statusG
查看日志 3308 的 log 如下,rep 复制用户无法连接到主节点。这时候才想起来之前修改过 root 和 rep 复制用户的密码,修改复制用户的密码导致主从复制中断,从节点无法连接到主库。从库 IO 线程状态为 “Replica_IO_Running: Connecting”。
2023-10-13T14:51:57.414780+08:00 5 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'rep@192.168.77.86:3306' - retry-time: 60 retries: 13 message: Access denied for user 'rep'@'192.168.77.86' (using password: YES), Error_code: MY-001045
解决办法
登录到从节点,停止复制,使用 change master to 命令修改复制用户密码。其他从节点依法炮制。
stop replica;
change master to master_password='MySQL8.0';
start replica;
show replica statusG
注意:“change master to”命令也即将过期,从 MySQL 8.0.23 开始是“CHANGE REPLICATION SOURCE TO”。“master_password” 命令也被 “SOURCE_PASSWORD” 所替代。
--附录:CHANGE REPLICATION SOURCE TO 完整命令
CHANGE REPLICATION SOURCE TO option [, option] ... [ channel_option ]
option: {
SOURCE_BIND = 'interface_name'
| SOURCE_HOST = 'host_name'
| SOURCE_USER = 'user_name'
| SOURCE_PASSWORD = 'password'
| SOURCE_PORT = port_num
| PRIVILEGE_CHECKS_USER = {NULL | 'account'}
| REQUIRE_ROW_FORMAT = {0|1}
| REQUIRE_TABLE_PRIMARY_KEY_CHECK = {STREAM | ON | OFF | GENERATE}
| ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = {OFF | LOCAL | uuid}
| SOURCE_LOG_FILE = 'source_log_name'
| SOURCE_LOG_POS = source_log_pos
| SOURCE_AUTO_POSITION = {0|1}
| RELAY_LOG_FILE = 'relay_log_name'
| RELAY_LOG_POS = relay_log_pos
| SOURCE_HEARTBEAT_PERIOD = interval
| SOURCE_CONNECT_RETRY = interval
| SOURCE_RETRY_COUNT = count
| SOURCE_CONNECTION_AUTO_FAILOVER = {0|1}
| SOURCE_DELAY = interval
| SOURCE_COMPRESSION_ALGORITHMS = 'algorithm[,algorithm][,algorithm]'
| SOURCE_ZSTD_COMPRESSION_LEVEL = level
| SOURCE_SSL = {0|1}
| SOURCE_SSL_CA = 'ca_file_name'
| SOURCE_SSL_CAPATH = 'ca_directory_name'
| SOURCE_SSL_CERT = 'cert_file_name'
| SOURCE_SSL_CRL = 'crl_file_name'
| SOURCE_SSL_CRLPATH = 'crl_directory_name'
| SOURCE_SSL_KEY = 'key_file_name'
| SOURCE_SSL_CIPHER = 'cipher_list'
| SOURCE_SSL_VERIFY_SERVER_CERT = {0|1}
| SOURCE_TLS_VERSION = 'protocol_list'
| SOURCE_TLS_CIPHERSUITES = 'ciphersuite_list'
| SOURCE_PUBLIC_KEY_PATH = 'key_file_name'
| GET_SOURCE_PUBLIC_KEY = {0|1}
| NETWORK_NAMESPACE = 'namespace'
| IGNORE_SERVER_IDS = (server_id_list),
| GTID_ONLY = {0|1}
}
channel_option:
FOR CHANNEL channel
server_id_list:
[server_id [, server_id] ... ]
参考链接
https://dev.mysql.com/doc/refman/8.0/en/change-master-to.html
https://dev.mysql.com/doc/refman/8.1/en/change-replication-source-to.html
全文完,希望可以帮到正在阅读的你,如果觉得此文对你有帮助,可以分享给你身边的朋友,同事,你关心谁就分享给谁,一起学习共同进步~~~
欢迎关注我的公众号【JiekeXu DBA之路】,第一时间一起学习新知识!
————————————————————————————
公众号:JiekeXu DBA之路
CSDN :https://blog.csdn.net/JiekeXu
墨天轮:https://www.modb.pro/u/4347
腾讯云:https://cloud.tencent.com/developer/user/5645107
————————————————————————————