一、主数据库器配置
假设主数据库IP地址为:192.168.1.1
修改my.cnf
在[mysqld]下增加配置
server-id=1
log-bin=syslog ##################################### 开启日志
binlog-do-db=cmstop ############################### 执行复制的数据库
binlog-ignore-db=mysql ############################# 不执行复制的数据库
binlog-ignore-db=test ############################### 不执行复制的数据库
binlog-ignore-db=information_schema ################### 不执行复制的数据库
log-bin=syslog ##################################### 开启日志
binlog-do-db=cmstop ############################### 执行复制的数据库
binlog-ignore-db=mysql ############################# 不执行复制的数据库
binlog-ignore-db=test ############################### 不执行复制的数据库
binlog-ignore-db=information_schema ################### 不执行复制的数据库
保存修改 重启MySQL
登陆主服务器
授权复制用户 grant replication slave on *.* to ‘t_user‘@‘192.168.1.2‘ identified by ‘123456‘ with grant option;
查看状态 show master status;
mysql> show master status;
+---------------+----------+--------------+-------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+-------------------------------+
| binlog.000005 | 639 | cmstop | mysql,test,information_schema |
+---------------+----------+--------------+-------------------------------+
1 row in set (0.00 sec)
+---------------+----------+--------------+-------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+-------------------------------+
| binlog.000005 | 639 | cmstop | mysql,test,information_schema |
+---------------+----------+--------------+-------------------------------+
1 row in set (0.00 sec)
记下file,position的值
二、从数据库配置
假设主数据库IP地址为:192.168.1.2
修改my.cnf
在[mysqld]下增加配置
server-id=2
replicate-do-db=cmstop
(由于MySQL已经不支持master-host,master-user类似的参数 所以不在my.cnf添加这些配置)
登陆从数据库 配置host等信息
change
master to
master_host=‘192.168.1.1‘,master_user=‘t_user‘,master_password=‘123456‘,master_log_file=‘syslog.000005‘,master_log_pos=639;
start slave;
查看状态 show slave status\G;
看有无报错
若复制不成功 可修改权限为(grant select,insert,update,delete,replication slave on *.* to ‘t_user‘@‘192.168.1.2‘ identified by ‘123456‘ with grant option;)