Mysql主从架构搭建
节点设置
192.168.148.133
192.168.148.134
修改配置文件
- 进入配置文件
vim /etc/my.cnf
2.主节点加入配置
log-bin=mysql-bin
server-id=1
binlog-do-db=mysql
expire-logs-days=10
slave-skip-error=all
3.从节点加入配置(配置后可以形成菊花链,也可不配置)
log-bin=mysql-bin
server-id=2
binlog-do-db=mysql
expire-logs-days=10
slave-skip-errors=all
4.重启mysql
systemctl restart mysqld
5.登录数据库,查看配置是否生效
show variables like 'server_id'
配置主从
- 查看主节点配置文件
show master status;
2.配置从节点
mysql> change master to master_host='192.168.148.134',
master_user='root',
master_password='password',
master_log_file='mysql-bin.000004',
master_log_pos=157;
Query OK, 0 rows affected, 8 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)
- 查看从节点配置文件
show slave status\G;
#均为yes,表示连接成功,这里出现了很多问题,踩了好多坑 Slave_IO_Running: Yes Slave_SQL_Running: Yes
|