mysql5.7主从复制
时间: 2023-08-16 15:09:31 浏览: 173
MySQL 5.7主从复制
MySQL 5.7的主从复制配置步骤如下:
1. 在主库上重启MySQL服务并进入MySQL控制台。创建一个用于从库复制的用户,并为其授权。
```
CREATE USER 'slave'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
```
2. 在主库上查看主库参数,记住File和Position对应的参数值,从库需要配置这些参数。
```
show master status;
```
3. 在从库上重启MySQL服务并进入MySQL控制台。配置主库参数,将master_log_file设置为主库的File值,将master_log_pos设置为主库的Position值。
```
change master to master_host='192.168.1.15', master_user='slave', master_password='123456', master_port=3306, master_log_file='mysql-bin.000003', master_log_pos=2336, master_connect_retry=30;
```
4. 在从库上启动主从复制。
```
start slave;
```
5. 查看主从复制状态,确保Slave_IO_Running和Slave_SQL_Running都为Yes。
```
show slave status \G;
```
6. 若要修改MySQL配置文件,进入配置文件中的部分,插入或修改以下关键配置:
```
[mysqld]
log-bin=mysql-bin
server-id=1
```
请确保在配置主从复制之前,主库和从库之间可以正常通信,且主库的binlog模式已经开启。当主从复制配置成功后,从库会自动从主库同步数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [MySQL 5.7 主从复制](https://blog.csdn.net/MrYang_Wei/article/details/129587645)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [MySQL5.7主从复制](https://blog.csdn.net/qq_43681755/article/details/108365639)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文