MySQL主從複製配置

服務器地址

主服務器:192.168.0.21
從服務器:192.168.0.22mysql

主服務器配置

修改my.cnf中以下配置:sql

server_id = 1

log_bin=mysql-bin

expire-logs-days=30
binlog-do-db=yliyun
binlog-do-db=yliyun_log
binlog-ignore-db=test

登入mysql
建立複製用戶並受權:服務器

grant replication slave on *.* to 'rep'@'192.168.0.22' identified by 'yliyun123';

查看日誌狀態:ide

show master status;

+------------------+----------+-------------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB      | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+-------------------+------------------+-------------------+
| mysql-bin.000026 |   539641 | yliyun,yliyun_log | test             |                   |
+------------------+----------+-------------------+------------------+-------------------+

從服務器配置

修改my.cnf中以下配置:日誌

server_id = 2

登入mysql
設置主服務器及日誌信息:code

change master to master_host='192.168.0.21', master_user='rep', master_password='yliyun123', master_log_file='mysql-bin.000026', master_log_pos=539641;

開始複製:server

start slave;

查看複製狀態:it

show slave status\G;
相關文章
相關標籤/搜索