背景:
master:192.168.100.231 MySQL5.0.19 Linux
slave: 192.168.100.234 MySQL5.0.18 Linux
step1) 配置master
在/etc/init.d MySQLd段加入
#(要同步的數據庫)
binlog_do_db = test
並確保
server-id=1
log-bin=MySQL-bin
step2) 授權slave
GRANT REPLICATION SLAVE ON *.* TO [email protected] IDENTIFIED BY '123';
重啟master
step3)配置slave
vi /etc/my.cnf
設置下面4行
server-id = 2
master-host = 192.168.100.231
master-user = test
master-passWord = 123
重啟發現slave的I/O線程工作正常,而SQL線程不工作
報了很怪的錯誤
070307 16:30:27 [ERROR] Slave: Error 'Table 'passport.loginuser' doesn't exist' on query. Default database: 'passport'. Query: 'delete from loginuser where tokenRefreshTime<='2006-07-03 07:00:00'', Error_code: 1146
070307 16:30:27 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'MySQL-bin.000001' position 98
因該是relay log中的數據有問題,於是在
將master機器上的數據拷到244,發現還是有問題。
於是在/etc/my.cnf中加入
replicate-do-db=test
重啟slave,
show slave status發現兩個線程工作正常
5)測試
在master的test數據的user表中添加了一條記錄
然後在slave上通過show processlist看slave工作情況一切正常,
再查數據庫數據似乎沒有更新,查看slave錯誤日志
070307 16:45:16 [ERROR] Slave: Error 'Can't create database 'test'; database exists' on query. Default database: 'test'. Query: 'create database test', Error_code: 1007
070307 16:45:16 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'MySQL-bin.000040' position 70671
原來都是我當初拷貝數據惹的禍,因為主機日志在我建數據庫的時候就開始了,所以我拷貝數據多此一舉,於是
我刪除拷貝的數據庫,一切ok