配置文件添加
```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`的变化。