主从复制原理
● Master 数据库只要发生变化,立马记录到Binary log 日志文件中
● Slave数据库启动一个I/O thread连接Master数据库,请求Master变化的二进制日志
● Slave I/O获取到的二进制日志,保存到自己的Relay log 日志文件中。
● Slave 有一个 SQL thread定时检查Realy log是否变化,变化那么就更新数据
主从复制" />
主从复制配置
[mysqld]
server-id = 1 # 节点ID,确保唯一
log-bin = master-bin #开启mysql的binlog日志功能
[mysqld]
server-id=2
relay-log=mysql-relay-bin
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=sys.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%
CREATE USER 'xxx'@'xxx' IDENTIFIED BY 'xxx';
grant replication slave on *.* to 'xxx'@'xxx'
FLUSH PRIVILEGES;
- slave数据库配置主库信息
CHANGE MASTER TO
MASTER_HOST = 'xxx',
MASTER_USER = 'xxx',
MASTER_PASSWORD = 'xxx',
MASTER_PORT = 3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=1111,
MASTER_HEARTBEAT_PERIOD = 10000;
- 启动从库slave进程
mysql> start slave;