一、环境
master:192.168.12.30
MYSQL版本:5.5
slave: 192.168.12.25
MYSQL版本:5.5
二、master操作
1、修改my.ini
##############
server-id=1
log-bin=c:\mysql\logs\mysql_log
binlog-do-db=test
binlog-ignore-db=mysql
##############
说明
c:\mysql\logs\mysql_log新建
binlog-do-db=test 允许同步的数据库
binlog-ignore-db=mysql 不允许同步的数据库
2、然后重启mysql
net stop\start mysql
3、在master上增加一个同步的用户名
mysql> GRANT REPLICATION SLAVE ON *.* TO ‘sync’@'192.168.12.25’ IDENTIFIED BY ‘123456′;
4、master上要同步的数据库先导入到192.168.12.25一份(一定要保持表结构一致,否则无法同步)
5、mysql> show master status;
+-------------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------------+----------+--------------+------------------+
| mysql_log.000002 | 107 | test | mysql |
+-------------------------+----------+--------------+------------------+
三、slave操作
1、修改slave的my.ini
####################
log-bin=c:\mysql\logs\mysql_log
server-id=2
master-host=192.168.12.30
master-user=sync
master-password=123456
master-connect-retry=60
replicate-do-db=test
replicate-ignore-db=mysql
####################
说明:
master-host=192.168.12.30 #master的IP
master-user=sync #master上作为同步用的用户名
master-password=123456 #同步用户名的密码
master-connect-retry=60 #设置同步的时间
replicate-do-db=test #需要同步的数据库
replicate-ignore-db=mysql #被忽略的数据库
3、重新启用mysql
无法启动 mysql,1067错误
删除 文件以下内容,重启服务
master-host=192.168.12.30
master-user=sync
master-password=123456
master-connect-retry=60
改用命令
mysql> CHANGE MASTER TO MASTER_HOST='192.168.12.30',MASTER_USER='sync',MASTER_PA
SSWORD='123456';
再重启
mysql> slave start;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.12.30
Master_User: sync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_log.000005
Read_Master_Log_Pos: 107
Relay_Log_File: ias-yuanyang-relay-bin.000006
Relay_Log_Pos: 260
Relay_Master_Log_File: mysql_binary_log.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 3061
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
slave服务配置成功;
操作192.168.12.30表数据,同步成功;
后记:不解为什么配置加在文件中导致slave服务启动不了?网上相关资料都是在配置文件中,难道跟系统有关吗。(MySQL的5.5版本已经不支持在my.ini中配置同步的主机信息了,即master-host等字段,否则MySQL会启不动,这点要注意下);
参考 :http://blog.donews.com/zzw45/archive/2006/02/13/724515.aspx
http://blog.sina.com.cn/s/blog_4c197d420100w7uz.html
http://wenku.baidu.com/link?url=kV2ZD31ySEeyz0TrN0vHH07NCRz2MB5MWr0dKybL2PBE4ZszwgxT0sl-vf-nW2bTILoIpx9NsaNY_i67RqY7vZa8tdey-VUItUHZe9akQNm