MySQL主从复制的流程(如下图):
- 主库会生成一个log dump 线程,用来给从库传binlog;
- 从库会生成两个线程,一个是I/O线程,一个是SQL线程;
- I/O线程会去请求主库的binlog,并将得到的binlog写入到 relay log(中继日志)文件中;
- SQL线程会读取 relay log文件中日志,并解析成具体操作,来实现主从复制;
主库 配置 /etc/my.cnf 修改
[mysqld] server-id=1 log_bin=mysql-bin binlog-ignore-db=mysql binlog-ignore-db=test binlog-ignore-db=information_schema binlog-ignore-db=sys
从库slave配置
[mysqld] server-id=2 log-bin=/var/lib/mysql/mysql-bin relay-log=/var/lib/mysql/salve-relay-bin read-only=on
执行:start slave;
参考文档:[https://dev.mysql.com/doc/refman/5.7/en/replication-howto-additionalslaves.html]
出现CHANGE MASTER TO 问题解决:[https://dev.mysql.com/doc/refman/5.7/en/replication-setup-slaves.html]
MySQL中的各种log说明,参考:
[https://www.cnblogs.com/myseries/p/10728533.html]
[https://www.cnblogs.com/f-ck-need-u/p/9001061.html]