当前位置: 首页 > news >正文

mysql主从报错:Last_IO_Error: Error connecting to source解决方法

目录

报错

处理方法

1.从库停止同步

2.主库修改my.cnf  生效配置default-authentication-plugin=mysql_native_password

3.重启服务重新创建复制用户

4.重新同步

5.测试主从


报错


 Last_IO_Error: Error connecting to source 'repl_user@192.168.213.15:3306'. This was attempt 3/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.

处理方法

1.从库停止同步


mysql> stop slave;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

2.主库修改my.cnf  生效配置default-authentication-plugin=mysql_native_password


[root@ms-server1 ~]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
--把这行注释去掉
default-authentication-plugin=mysql_native_password
bind-address=0.0.0.0
default-storage-engine=Innodb
innodb_buffer_pool_size = 2048M

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

server_id=1
log-bin=mysql-bin

3.重启服务重新创建复制用户

[root@ms-server1 ~]# systemctl restart mysqld
删除之前创建的复制用户
mysql> drop user  'repl_user'@'%' ;
Query OK, 0 rows affected (0.01 sec)

重新创建用户
use mysql
create user 'repl_user'@'%' identified by 'Antute_123';
grant replication slave on *.* to 'repl_user'@'%';
flush privileges;

4.重新同步

主库查看新状态
show master status\G;
mysql> show master status\G;
*************************** 1. row ***************************
             File: mysql-bin.000003
         Position: 1023
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)

ERROR:
No query specified


从库修改my.cnf配置 default-authentication-plugin=mysql_native_password
[root@ms-server2 ~]# vi /etc/my.cnf
[root@ms-server2 ~]# cat /etc/my.cnf
[mysqld]

default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

server_id=2
log-bin=mysql-bin
重启数据库服务
[root@ms-server2 ~]# systemctl restart mysqld
按照主库当前的状态进行复制
CHANGE MASTER TO MASTER_HOST='192.168.213.15', MASTER_USER='repl_user' ,MASTER_PASSWORD='Antute_123',MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=1023;


mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> CHANGE MASTER TO MASTER_HOST='192.168.213.15', MASTER_USER='repl_user' ,MASTER_PASSWORD='Antute_123',MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=1023;
Query OK, 0 rows affected, 8 warnings (0.01 sec)


mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)
重新查看状态同步正常
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 192.168.213.15
                  Master_User: repl_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 1023
               Relay_Log_File: ms-server2-relay-bin.000002
                Relay_Log_Pos: 326
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes --显示yes为正常
            Slave_SQL_Running: Yes --显示yes为正常

5.测试主从


主库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| antute_db          |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use antute_db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>

mysql> show create table user\G;
*************************** 1. row ***************************
       Table: user
Create Table: CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL COMMENT '用户名',
  `role_id` int DEFAULT NULL COMMENT '角色id',
  `password` varchar(255) DEFAULT NULL COMMENT '密码',
  `salt` varchar(255) DEFAULT NULL COMMENT '盐',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=37794282 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

ERROR:
No query specified
主库插入一条数据
mysql> insert into user values(1001,'dadada',10010,'abcd123','ssss');
Query OK, 1 row affected (0.00 sec)


从库查询该表
mysql> use antute_db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
查询无误同步正常
mysql> select * from user;
+------+----------+---------+----------+------+
| id   | username | role_id | password | salt |
+------+----------+---------+----------+------+
| 1001 | dadada   |   10010 | abcd123  | ssss |
+------+----------+---------+----------+------+
1 row in set (0.00 sec)

mysql>
 

相关文章:

  • 京东ES支持ZSTD压缩算法上线了:高性能,低成本 | 京东云技术团队
  • 限制API接口访问速率
  • 大语言模型系列-BERT
  • DNS - 全家桶(114 DNS、阿里DNS、百度DNS 、360 DNS、Google DNS)
  • 图像处理:孤立点的检测
  • rust获取本地ip地址的方法
  • 基于小波多普勒变换的回波信号检测matlab仿真
  • 技术进化与经济互动的深刻洞察——《技术的本质》读书笔记
  • 2000W双向逆变器介绍
  • 运动型蓝牙耳机推荐哪款?2024运动耳机排行榜最新
  • CentOS 7.9 安装图解
  • ReactNative中样式与布局的书写
  • 架设一台NFS服务器,并按照以下要求配置
  • VR远程的实现
  • MySQL Update语句一个非常经典的“坑”
  • 【407天】跃迁之路——程序员高效学习方法论探索系列(实验阶段164-2018.03.19)...
  • 5、React组件事件详解
  • 5分钟即可掌握的前端高效利器:JavaScript 策略模式
  • Angular 响应式表单 基础例子
  • GDB 调试 Mysql 实战(三)优先队列排序算法中的行记录长度统计是怎么来的(上)...
  • iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
  • LeetCode算法系列_0891_子序列宽度之和
  • mongo索引构建
  • 如何选择开源的机器学习框架?
  • 项目实战-Api的解决方案
  • 在GitHub多个账号上使用不同的SSH的配置方法
  • 阿里云ACE认证之理解CDN技术
  • 进程与线程(三)——进程/线程间通信
  • 数据库巡检项
  • ​TypeScript都不会用,也敢说会前端?
  • #etcd#安装时出错
  • #Linux(权限管理)
  • (Java岗)秋招打卡!一本学历拿下美团、阿里、快手、米哈游offer
  • (二)什么是Vite——Vite 和 Webpack 区别(冷启动)
  • (附源码)小程序 交通违法举报系统 毕业设计 242045
  • (汇总)os模块以及shutil模块对文件的操作
  • (区间dp) (经典例题) 石子合并
  • (三)elasticsearch 源码之启动流程分析
  • (十七)Flask之大型项目目录结构示例【二扣蓝图】
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • (转)Mysql的优化设置
  • (转)大道至简,职场上做人做事做管理
  • .NET 5.0正式发布,有什么功能特性(翻译)
  • .Net core 6.0 升8.0
  • @Mapper作用
  • [Android]Android P(9) WIFI学习笔记 - 扫描 (1)
  • [Android]竖直滑动选择器WheelView的实现
  • [C++]命名空间等——喵喵要吃C嘎嘎
  • [C++从入门到精通] 14.虚函数、纯虚函数和虚析构(virtual)
  • [HTML API]HTMLCollection
  • [HTML]Web前端开发技术30(HTML5、CSS3、JavaScript )JavaScript基础——喵喵画网页
  • [Java][Android][Process] 暴力的服务能够解决一切,暴力的方式运行命令行语句
  • [javaSE] 数据结构(二叉查找树-插入节点)
  • [Leetcode] 寻找数组的中心索引
  • [Linux]进程间通信(system V共享内存 | system V信号量)