mysql搭建简单主从时的常见错误

本文介绍了MySQL中关于Slave_IO_Running:No和连接Master的错误,包括server_id配置问题、网络连接、密码加密、GTID管理以及处理误操作的方法。提供了解决方案,如修改配置、检查网络和授权等。
摘要由CSDN通过智能技术生成

Slave_IO_Running: No

报错:

Last_IO_Error: Fatal error: The replica I/O thread stops because source and replica have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on replica but this does not always make sense; please check the manual before using it).

 这种报错是因为你的配置文件中server_id这个选项要么没有或者重复。

解决方案:

  1. 修改/etc/my.cnf或子配置文件中server_id项,id的值主从不能没有或一样

Slave_IO_Running: Connecting

报错:

Last_IO_Error: error connecting to master 'rep@192.168.150.21:3306' - retry-time: 60 retries: 1 message: Can't connect to MySQL server on '192.168.150.21:3306' (111)

 出现这种错误的原因比较多需要排除:

解决方案:

1.保证两台服务器在同一网段或者可以互相通信

[root@localhost ~]# mysqladmin -urep -p123456 -h192.168.150.21 ping
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive

2.yo

       # 查询日志
[root@localhost ~]# tail /var/log/mysql/mysqld.log
...
2023-12-02T03:17:53.631813Z 5 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'rep@192.168.150.21:3306' - retry-time: 60 retries: 3 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061

 方案一:修改master库的密码加密方式

mysql> alter user 'rep'@'192.168.150.%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)

方案二:设置从库的change master 时加get_master_public_key=1参数

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

mysql> change master to
    -> master_host='192.168.20.149',
    -> master_user='rep',
    -> master_password='123456',
    -> master_log_file='binlog.000006',
    -> master_log_pos=676,
    -> get_master_public_key=1;  #加入这个参数
Query OK, 0 rows affected, 9 warnings (0.00 sec)

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

 GTID 从库误写入操作处理

查看监控信息:
Last_SQL_Error: Error 'Can't create database 'db4'; database exists' on query. Default database: 'db4'. Query: 'create database db4'

Retrieved_Gtid_Set: 71bfa52e-4aae-11e9-ab8c-000c293b577e:1-3
Executed_Gtid_Set:  71bfa52e-4aae-11e9-ab8c-000c293b577e:1-2,
7ca4a2b7-4aae-11e9-859d-000c298720f6:1

注入空事物的方法:

stop slave;
set gtid_next='99279e1e-61b7-11e9-a9fc-000c2928f5dd:3';
begin;commit;
set gtid_next='AUTOMATIC';
    
这里的xxxxx:N 也就是你的slave sql thread报错的GTID,或者说是你想要跳过的GTID。
最好的解决方案:重新构建主从环境

 其他情况还有待研究,一般情况如上解决,error因人而异,自己要多看报错提示,很多时候报错都出现在小细节上面

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL Shell 是 MySQL 官方提供的一款基于 Python 和 JavaScript 开发的交互式 Shell 工具,可以用于管理 MySQL 数据库、执行 SQL 语句、监控 MySQL 实例等。在 MySQL Shell 中,可以使用内置的 ReplicationShell 插件来搭建主从复制。 以下是在 MySQL Shell 中搭建主从复制的步骤: 1. 安装 MySQL Shell 首先需要安装 MySQL Shell。可以在 MySQL 官网下载对应平台的安装包,或者使用操作系统自带的包管理器进行安装。安装完成后,可以通过以下命令启动 MySQL Shell: ``` $ mysqlsh ``` 2. 连接到主服务器 在 MySQL Shell 中,可以通过以下命令连接到主服务器: ``` mysql-js> \connect root@localhost:3306 ``` 其中,`root` 是连接到主服务器的用户名,`localhost` 是主服务器的地址,`3306` 是主服务器的端口号。连接成功后,可以使用以下命令检查主服务器的配置: ``` mysql-js> \sql mysql-sql> SHOW MASTER STATUS; ``` 该命令将显示当前主服务器的二进制日志文件和位置,用于后续配置从服务器。 3. 连接到从服务器 在 MySQL Shell 中,可以通过以下命令连接到从服务器: ``` mysql-js> \connect root@localhost:3307 ``` 其中,`root` 是连接到从服务器的用户名,`localhost` 是从服务器的地址,`3307` 是从服务器的端口号。连接成功后,可以使用以下命令配置从服务器的复制: ``` mysql-js> \sql mysql-sql> CHANGE MASTER TO MASTER_HOST='localhost', MASTER_PORT=3306, MASTER_USER='root', MASTER_PASSWORD='password', MASTER_LOG_FILE='[主服务器的二进制日志文件名]', MASTER_LOG_POS=[主服务器的二进制日志位置]; mysql-sql> START SLAVE; ``` 其中,`localhost` 和 `3306` 分别是主服务器的地址和端口号,`root` 和 `password` 分别是连接到主服务器的用户名和密码,`[主服务器的二进制日志文件名]` 和 `[主服务器的二进制日志位置]` 是主服务器当前二进制日志的文件名和位置。执行以上命令后,从服务器就会开始复制主服务器的数据。 4. 检查主从复制状态 可以使用以下命令检查主从复制状态: ``` mysql-sql> SHOW SLAVE STATUS\G ``` 如果显示 `Slave_IO_Running` 和 `Slave_SQL_Running` 都为 `YES`,则表示主从复制配置成功。 希望以上步骤对您有所帮助!如有任何疑问,欢迎随追问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值