「MySQL」- 搭建主从复制(基于位置复制)

  CREATED BY JENKINSBOT

第一步、修改配置(主库)

修改主库配置文件,以启用 binlog 功能:

[mysqld]
server_id = 26
log_bin = /var/log/mysql/binlog
binlog_format = ROW
expire_logs_days = 30
max_binlog_size = 500M
sync_binlog = 1

创建用于复制的用户,从库将使用该用户进行复制:

GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%' IDENTIFIED BY 'XXXXXXXX';

至此启动数据服务即可。

第二步、修改配置(从库)

从库配置文件:

[mysqld]
server_id = 27
relay_log = /var/log/mysql/relay_log

启动数据库服务。

第三步、启用从库复制

STOP SLAVE;

CHANGE MASTER TO master_host = 'host', master_port = 'port',
    master_user = 'username', master_password = 'password',
    master_log_file = 'binlog file', master_log_pos = 'position';

START SLAVE;