重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、小程序制作、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了双牌免费建站欢迎大家使用!
master | slave | |
---|---|---|
IP | 192.168.7.71 | 192.168.7.72 |
主机名 | master01 | slave01 |
OS | CentOS7 | CentOS7 |
MySQL版本 | 5.7.28 | 5.7.28 |
略
# vim /etc/my.cnf
[mysqld]
log-bin = mysql-bin
server-id = 1
# 重启服务
systemctl start mysqld
grant replication slave on *.* to repluser@'192.168.7.%' identified by '123.com';
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
[mysqld]
server-id = 2
read_only = ON #设为只读,但是对超级用户无效。
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.7.71',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='123.com',
-> MASTER_PORT=3306,
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=154;
mysql> start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.7.71
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 154
Relay_Log_File: slave01-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...省略信息...
master.info:用于保存slave连接至master时的相关信息,例如账号、密码、服务器地址等
relay-log.info:保存在当前slave节点上已经复制的当前二进制日志和本地relay log日志的对应关系