MySQL 主从复制 配置部署
时间: 2024-03-05 14:47:57 浏览: 78
MySQL 主从复制的配置部署包括以下步骤:
1. 配置主数据库
在主数据库中,需要开启二进制日志功能,以便记录所有的修改操作。具体的配置方法如下:
- 编辑 MySQL 配置文件 my.cnf,在 [mysqld] 段中添加以下配置:
```
log-bin=mysql-bin
server-id=1
```
log-bin 指定了二进制日志文件的名称前缀,server-id 指定了主数据库的唯一标识符。
- 重启 MySQL 服务,使配置生效。
2. 配置从数据库
在从数据库中,需要配置从数据库连接主数据库的相关参数。具体的配置方法如下:
- 编辑 MySQL 配置文件 my.cnf,在 [mysqld] 段中添加以下配置:
```
server-id=2
```
server-id 指定了从数据库的唯一标识符,需要与主数据库不同。
- 启动 MySQL 服务。
- 在从数据库中执行以下命令,连接主数据库:
```
CHANGE MASTER TO
MASTER_HOST='master_host_name',
MASTER_USER='replication_user_name',
MASTER_PASSWORD='replication_password',
MASTER_LOG_FILE='recorded_log_file_name',
MASTER_LOG_POS=recorded_log_position;
```
其中,MASTER_HOST 指定了主数据库的地址,MASTER_USER 和 MASTER_PASSWORD 指定了连接主数据库的用户名和密码,MASTER_LOG_FILE 和 MASTER_LOG_POS 指定了从数据库从哪个位置开始复制数据。
- 执行以下命令,开启从数据库的复制功能:
```
START SLAVE;
```
3. 测试主从复制
在主数据库中进行一些修改操作,例如插入一条记录。然后在从数据库中执行以下命令,查看是否同步了主数据库的数据:
```
SELECT * FROM replicated_table;
```
如果从数据库中能够看到刚才插入的记录,说明主从复制已经正常配置。
阅读全文
相关推荐
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044947.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)