1. 程式人生 > >mariadb配置主從複製

mariadb配置主從複製

本文章是通過docker建立了兩個mariadb的容器,主要是記錄,方便以後使用.....

1、master配置

a、修改/etc/my.cnf檔案

[mysqld]
server-id=1
log_bin=master-bin
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test
innodb_flush_log_at_trx_commit=1
binlog_format=mixed

備註:此配置一定要在[mysqld]之下

b、新增備份的賬號

mysql> grant replication slave on *.* to 'backup'@'%' identified by '123456';
mysql> flush privileges;

c、重啟mariadb

d、檢視記錄log_bin檔名和pos

2、slave配置

a、修改/etc/my.cnf檔案

[mysqld]
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
relay_log_recovery=1

b、重啟mariadb

c、配置slave相關引數

mysql> stop slave;
mysql> change master to 
       master_host='master IP',
       master_user='backup',
       master_password='123456',
       master_log_file='master-bin.000001',
       master_log_pos=245;
 mysql> start slave;

d、檢視是否配置成功

 mysql> show slave status\G