MySQL主从配置

一、主数据库器配置
假设主数据库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 ################### 不执行复制的数据库
保存修改 重启MySQL
登陆主服务器
--授权复制用户--
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的值
二、从数据库配置
假设主数据库IP地址为:192.168.1.2
修改my.cnf
在[mysqld]下增加配置
server-id=2
replicate-do-db=cmstop
(由于MySQL已经不支持master-host,master-user类似的参数 所以不在my.cnf添加这些配置)
登陆从数据库 配置host等信息
mysql> change master to master_host='192.168.1.1',master_user='t_user',master_password='123456',master_log_file='binlog.000005',master_log_pos=639;
start slave;
--查看状态-- 
mysql> show slave status
看有无报错
若复制不成功 可修改权限为
mysql> grant select,insert,update,delete,replication slave on *.* to 't_user'@'192.168.1.2' identified by '123456' with grant option;
取消主从配置

进入mysql

mysql> stop slave;

mysql> reset slave;

mysql> change master to master_user='', master_host=' ', master_password='';
注意 master_host=' ' 引号之间有空格
posted @ 2014-08-20 10:56  Youn丶  阅读(424)  评论(0编辑  收藏  举报