Maison > Article > base de données > MySQL5 master slave安装配置全过程
我们今天主要向大家介绍的是MySQL5 master slave安装配置的实际操作过程,我们在对MySQL5 master slave进行安装配置日志在以下的背景中,以下就是文章的具体内容的介绍,望你浏览之后会有所收获。 master:192.168.100.231 MySQL(和PHP搭配之最佳组合)5.0.19
我们今天主要向大家介绍的是MySQL5 master slave安装配置的实际操作过程,我们在对MySQL5 master slave进行安装配置日志在以下的背景中,以下就是文章的具体内容的介绍,望你浏览之后会有所收获。
master:192.168.100.231 MySQL(和PHP搭配之最佳组合)5.0.19 linux
slave: 192.168.100.234 MySQL(和PHP搭配之最佳组合)5.0.18 linux
step1) 配置master
在/etc/init.d MySQL(和PHP搭配之最佳组合)d段加入
要同步的数据库)
<ol class="dp-xml"><li class="alt"><span><span class="attribute">binlog_do_db</span><span> = </span><span class="attribute-value">test</span><span> </span></span></li></ol>
并确保
<ol class="dp-xml"> <li class="alt"><span><span class="attribute">server-id</span><span>=</span><span class="attribute-value">1</span><span> </span></span></li> <li> <span class="attribute">log-bin</span><span>=</span><span class="attribute-value">MySQL</span><span>(和PHP搭配之最佳组合)-bin </span> </li> <li class="alt"><span>step2) 授权slave </span></li> <li><span>GRANT REPLICATION SLAVE ON *.* TO test@192.168.100.234 IDENTIFIED BY '123'; </span></li> </ol>
重启master
step3)配置slave
vi /etc/my.cnf
设置下面4行
<ol class="dp-xml"> <li class="alt"><span><span class="attribute">server-id</span><span> = </span><span class="attribute-value">2</span><span> </span></span></li> <li> <span class="attribute">master-host</span><span> = </span><span class="attribute-value">192</span><span>.168.100.231 </span> </li> <li class="alt"> <span class="attribute">master-user</span><span> = </span><span class="attribute-value">test</span><span> </span> </li> <li> <span class="attribute">master-password</span><span> = </span><span class="attribute-value">123</span><span> </span> </li> </ol>
重启发现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
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(和PHP搭配之最佳组合)-bin.000001' position 98
因该是relay log中的数据有问题,于是在
将master机器上的数据拷到244,发现还是有问题。
于是在/etc/my.cnf中加入
<ol class="dp-xml"><li class="alt"><span><span class="attribute">replicate-do-db</span><span>=</span><span class="attribute-value">test</span><span> </span></span></li></ol>
MySQL5 master slave安装配置日志中需要重启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(和PHP搭配之最佳组合)-bin.000040' position 70671
原来都是我当初拷贝数据惹的祸,因为主机日志在我建数据库的时候就开始了,所以我拷贝数据多此一举,于是
我删除拷贝的数据库,一切ok
以上的相关内容就是对MySQL5 master slave安装配置日志的介绍,望你能有所收获。