[MySQL] MySQL8.0主从同步报错2061问题解决

背景:

CentOS7.3使用yum安装了MySQL8.0.14,根据官网教程创建了主从同步账号、设置主从同步后启动同步报错2061,错误日志

[root@ldap1 modules]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 72
Server version: 8.0.14 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.1.3
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 734
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 734
              Relay_Log_Space: 155
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2061
                Last_IO_Error: error connecting to master 'replication@192.168.1.3:3306' - retry-time: 60  retries: 12
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 0
                  Master_UUID: 
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 190129 14:09:22
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

mysql> 

 

问题排查:检查了主机和从机的网络、防火墙都没有问题,重新创建了同步账号再设置同步,问题仍然存在。再次查看官方文档,在网页的下方有很明确的提示:

MySQL8.0默认指定使用需要SSL的身份验证插件caching_sha2_password,而我们在创建同步复制账号时候没有指定REQUIRE SSL。为了降低这件事情的复杂性,我们选择了社区的解决方法,选择绕过SSL插件的验证,改为mysql_native_password验证来做同步复制。

 

解决:

重新创建MySQL复制账号,创建账号时指定身份验证方法

mysql> CREATE USER 'repl'@'192.168.1.3' IDENTIFIED WITH 'mysql_native_password' BY 'replicationPassword2019!';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.3';
mysql> FLUSH PRIVILEGES;

此时再查看该用户的密码加密方式,plugin为mysql_native_password

mysql> select user,host,plugin,authentication_string from user \G
*************************** 1. row ***************************
                 user: repl
                 host: 192.168.1.3
               plugin: mysql_native_password
authentication_string: *47C25685DDCE2754F1175C38F437961FF6C5AC53

 

再次设置同步成功

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.3
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 1035
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 322
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1035
              Relay_Log_Space: 530
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 84db9645-2372-11e9-8d9a-000c29d69195
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
1 row in set (0.00 sec)

mysql> 

 

参考:

https://blog.csdn.net/wangxiaotongfan/article/details/81870258

https://forums.mysql.com/read.php?26,663846,663880#msg-663880

 

 

### 关于 MySQL 8.0 主从同步源码 对于MySQL 8.0版本中的主从同步机制,在官方文档中提到`CHANGE MASTER TO`语句已经被弃用并建议使用`CHANGE REPLICATION SOURCE TO`来替代[^1]。这表明在查看相关源代码时,应当关注新的命令实现逻辑。 #### 源文件位置 MySQL的主从复制功能主要由几个核心模块构成: - **binlog事件处理**:位于`sql/binlog.cc`和`sql/rpl_binlog.h`等文件内。 - **IO线程管理**:涉及`sql/slave.cc`内的函数定义。 - **SQL执行线程**:同样可以在`sql/slave.cc`找到相应代码片段。 - **网络通信层**:负责master与slave之间的数据传输协议解析,这部分通常分布在多个头文件以及C++源文件之中。 针对新引入的变化如`CHANGE REPLICATION SOURCE TO`语句的支持,则需特别留意`sql/sql_yacc.yy`语法分析器部分及其关联的动作函数实现;另外还有可能是`rpl_rli_pdb.cc`等相关联的数据结构修改以适应新的API调用方式。 #### 修改点概览 随着MySQL不断迭代升级,特别是自8.0起对旧版指令进行了优化改进,因此如果要深入研究具体改动细节,可以从以下几个方面入手: - 查看提交记录(commit history),寻找有关移除`CHANGE MASTER TO`及新增`CHANGE REPLICATION SOURCE TO`的关键字条目。 - 对比不同分支间的差异对比图(diff graph),直观了解哪些地方做了调整。 - 阅读官方发布的release notes说明文档,获取更多背景信息和技术决策依据。 ```bash git clone https://github.com/mysql/mysql-server.git cd mysql-server git checkout 8.0 grep -rnw './' -e 'CHANGE REPLICATION SOURCE' ``` 上述命令可以帮助定位到具体的变更位置,并为进一步探索提供线索。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值