1. 创建数据库
- 主数据库:192.168.21.100
- 从数据库:192.168.21.101
2. 修改配置文件/etc/my.cnf
- 主数据库:
[mysqld] log-bin=mysql-bin server-id=100
- 从数据库:
[mysqld] server-id=101
修改完配置文件后,重启mysql服务使配置生效
3. 主库创建同步用户
- 在主数据库中使用如下sql语句创建从数据库使用的用户
create user 'slave'@'%' identified by '123456';
alter user 'slave'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'slave'@'%' with grant option;
- 查看主库二进制日志(binary log)的位置
show master status