主:192.168.1.101
从:192.168.1.111
OS CentOS 6.8
理论上需要主从服务器MySQL版本相同。
该方案已经实验并通过MySQL5.0.95-log 与 MySQL5.1.73-log。
查看MySQL版本:
show variables like 'version';
主(192.168.1.101)配置:
# 在 /etc/my.conf [mysqld] 下添加:
server-id=101 # 配置服务ID,必需唯一
log-bin=mysql-bin # 配置添加日志,并设置日志文件名前缀
binlog-ignore-db=mysql # 添加忽略日志记录的表
binlog-ignore-db=information_schema # 添加忽略日志记录的表
主(192.168.1.101)用户及权限:
grant replication slave, super, reload on *.* to 'rep'@'192.168.1.111' identified by 'passrep';
从(192.168.1.111)配置:
log-bin="/home/nginx/mysql-logs/bin/bin"
log-bin-index="/home/nginx/mysql-logs/index/index"
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
server-id=111
master-host=192.168.1.101
master-user=rep #同步用户帐号
master-password=passrep #同步用户密码
master-port=3306
master-connect-retry=60 #预设重试间隔60秒
replicate-do-db=target_db1 #告诉该slave只做target_db1数据库的更新
replicate-do-db=target_db2 #告诉该slave只做target_db2数据库的更新
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
log-slave-updates=1
slave-skip-errors=all
slave-net-timeout=60
从(192.168.1.101)用户及权限:
grant replication slave, super, reload on *.* to 'rep'@'192.168.1.111' identified by 'passrep';