配置文件添加
```properties
[mysqld]
server-id=1
log-bin=/opt/mysql3306/data/mysql3306-bin
```
1. server-id:配置服務器的唯一編號。在同一局域網內,保證id是唯一的。
2. log-bin:配置二進制數據文件的位置。
重啟MySQL
```bash
/path/to/mysql/bin/mysqld_safe --defaults-file=...../my.cnf &
```
創建用戶并授權
```mysql
CREATE USER 'slave'@'%' IDENTIFIED BY 'slave';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
```
查看主服務器狀態
```mysql
show master status;
```
```mysql
+----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| mysql3306-bin.000002 | 154 | | | |
+----------------------+----------+--------------+------------------+-------------------+
```
> 記錄下`File`和`Position`的值,并且不進行其他操作以免引起`Position`的變化。