blog/linux/linux环境搭建mysql主从集群

linux环境搭建mysql主从集群

环境

masterreplica
192.168.10.111192.168.10.112

安装完成mysql

# 启动mysql
service mysqld start
#
cd
# 进入mysql命令行
./mysql -uroot -p123456

use mysql
# 赋权限给从数据库
GRANT REPLICATION SLAVE ON *.* to root@192.168.10.112 identified by '123456';
show binary logs;
show master status\G;
reset master;

更改配置文件

vi /etc/my.cnf
#设置主192.168.10.111
server_id=111
#设置主192.168.10.112
server_id=112


# 清空日志文件,同Master
cd /usr/local/mysql/data
rm -rf mysql-bin.*

systemctl restart mysql



# 启用复制
# 让slave连接master并开始重做master二进制日志中的事件
./mysql -uroot -p123456

change master to master_host='192.168.10.111',master_user='root',master_password='123456',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=120;

start slave;
show slave status\G;

# 查看当前server_id

show variables like 'server_id';

show variables like '%server_uuid%';

# 其中Slave_IO_Running 与 Slave_SQL_Running 的值都必须为YES,才表明状态正常。

[错误] 其中Slave_IO_Running为NO Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
[解决] 在副本节点下执行

./mysql -uroot -p123456

show variables like '%server_uuid%';
mv /usr/local/mysql/data/mysql/auto.cnf /usr/local/mysql/data/mysql/auto.cnf.bk
# 重启副本节点
systemctl restart mysql

查看show slave status这样表示安装成功.

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

查看master集群上show slave hosts 下面表示成功

+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID |
+-----------+------+------+-----------+--------------------------------------+
| 101 | | 3306 | 1 | cfd1e2f2-85e0-11ea-83ab-525400c3ed77 |
+-----------+------+------+-----------+--------------------------------------+
本文总阅读量