Docs/数据库/mysql/主备复制.md
2022-10-18 16:59:37 +08:00

13 lines
No EOL
853 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

备库B和主库A之间维持了一个长连接。主库A内部有一个线程专门用于服务备库B的这个长连接。一个事务日志同步的完整过程如下
1.在备库B上通过change master命令设置主库A的IP、端口、用户名、密码以及要从哪个位置开始请求binlog这个位置包含文件名和日志偏移量
2.在备库B上执行start slave命令这时备库会启动两个线程io_thread和sql_thread。其中io_thread负责与主库建立连接
3.主库A校验完用户名、密码后开始按照备库B传过来的位置从本地读取binlog发给B
4.备库B拿到binlog后写到本地文件称为中转日志
5.sql_thread读取中转日志解析出日志里的命令并执行
由于多线程复制方案的引入sql_thread演化成了多个线程