在虚拟机中克隆Linux系统后出现的bug:
本想在一台电脑上,使用虚拟机克隆出两个一样的Linux系统,一个做主数据库,一个做从数据库,实现MySQL的主从复制。
但是克隆后会出现各种各样的bug,这里我遇到了这两个,记录一下。
克隆的教程请看这个博主写的:Linux下虚拟机的克隆(CentOS为例)
亲测实用
1.Slave_IO_Running: Connecting:
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 129.168.61.129
Master_User: zhc
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 436
Relay_Log_File: localhost-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Connecting #这里出现Connecting
Slave_SQL_Running: Yes
---
# 原因分析:出现这个,大概率是自己操作不规范造成的。
解决方案:
1.查看在从数据库中输入的这条语句,每个属性都根据自己的实际情况一一对应,千万别打错了!!!!:
mysql> change master to
master_host='129.168.61.129', #主数据库的id地址
master_user='zhc', #主数据库允许的用户名
master_password='Root@123456', # 密码
master_log_file='mysql-bin.000001', #通过 show master status;查看主数据
master_log_pos=648; #通过 show master status;查看主数据
2.克隆的Linux系统 数据库的uuid一样,也可能出现该bug,因此需要修改uuid;
```bash
[root@localhost ~]# cat /var/lib/mysql/auto.cnf #查看MySQL的uuid
[root@localhost ~]# uuidgen #生成一个uuid
[root@localhost ~]# vim /var/lib/mysql/auto.cnf #修改uui
2.Slave_IO_Running: Connecting:
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.61.129
Master_User: zhc
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 648
Relay_Log_File: localhost-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: Yes
``# 原因分析:出现这个bug,最好按照流程在操作一遍。
解决方案:
1.对主数据库操作:
mysql> show master status; #查看状态
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 684 | | | |
+------------------+----------+--------------+------------------+-------------------+
mysql> flush logs; #刷新日志
Query OK, 0 rows affected (0.01 sec)
mysql> show master status; #再次查看 记录下此时的File 和 Position
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 982 | | | |
+------------------+----------+--------------+------------------+-------------------+
2.对从数据库的操作:
mysql> stop slave; #先停掉之前的线程
Query OK, 0 rows affected (0.00 sec)
mysql> change master to
master_host='192.168.61.129',
master_user='zhc',
master_password='Root@123456',
master_log_file='mysql-bin.000003', #主数据库查出来的File
master_log_pos=982; # 主数据库查出来的Position
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> start slave; #再次启动从线程
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.61.129
Master_User: zhc
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 982
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
启动成功