﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-工作笔记-随笔分类-原创文章</title><link>http://www.cnitblog.com/guhaiyun/category/6979.html</link><description>--Henry@Moliyo_2008</description><language>zh-cn</language><lastBuildDate>Fri, 30 Sep 2011 23:53:25 GMT</lastBuildDate><pubDate>Fri, 30 Sep 2011 23:53:25 GMT</pubDate><ttl>60</ttl><item><title>Mysql Replacation配置最简文档</title><link>http://www.cnitblog.com/guhaiyun/archive/2008/03/28/41612.html</link><dc:creator>Henry</dc:creator><author>Henry</author><pubDate>Fri, 28 Mar 2008 02:57:00 GMT</pubDate><guid>http://www.cnitblog.com/guhaiyun/archive/2008/03/28/41612.html</guid><wfw:comment>http://www.cnitblog.com/guhaiyun/comments/41612.html</wfw:comment><comments>http://www.cnitblog.com/guhaiyun/archive/2008/03/28/41612.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/guhaiyun/comments/commentRss/41612.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/guhaiyun/services/trackbacks/41612.html</trackback:ping><description><![CDATA[<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">系统环境<br>Windows xp sp2<br>安装路径<br>D:/Program Files/MySQL/MySQL Server 5.0/<br>Mysql版本<br>5.1.23-rc-community-log</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">配置主库ini文件<br>port=3306<br>datadir="D:/Program Files/MySQL/MySQL Server 5.0/Data/"</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">server-id=1<br>log-bin=mysql-bin.log</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">配置从库ini文件<br>port=3307<br>datadir="D:/Program Files/MySQL/MySQL Server 5.0/Data2/"</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">server-id=2<br>log-slave-updates<br>replicate-do-db=dbname</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">命令行启动主库<br>&gt;mysqld-nt --defaults-file="..\my.ini"</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">连接到主库，创建Replacation用户<br>&gt;mysql -uroot -ppassword -P3306</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">mysql&gt;grant replication slave on *.* to <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#39;&#114;&#101;&#112;&#39;&#64;&#39;&#108;&#111;&#99;&#97;&#108;&#104;&#111;&#115;&#116;&#39;">'rep'@'localhost'</a> identified by 'rep';</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">锁住主库的table，以便备份数据文件到从库进行初始化<br>mysql&gt;flush tables with read lock;</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">显示主库状态，注意记下当前二进制日志文件名和position<br>mysql&gt; show master status;</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">将D:/Program Files/MySQL/MySQL Server 5.0/Data/下的内容打包复制到D:/Program Files/MySQL/MySQL Server 5.0/Data2/下，执行从库的初始化。当然，初始化也可以使用mysqldump来完成。<br>另外开启一个cmd，启动从库<br>&gt;mysqld-nt --defaults-file=my2.ini</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">连接到从库进行配置,注意到这里master_log_file和master_log_pos就是前面show master status的结果<br>&gt;mysql -uroot -ppassword -P3307</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">mysql&gt; CHANGE MASTER TO<br>&nbsp;&nbsp; &nbsp;-&gt; MASTER_HOST='localhost',<br>&nbsp;&nbsp; &nbsp;-&gt; MASTER_USER='rep',<br>&nbsp;&nbsp; &nbsp;-&gt; MASTER_PASSWORD='rep',<br>&nbsp;&nbsp; &nbsp;-&gt; MASTER_LOG_FILE='mysql-bin.000002',<br>&nbsp;&nbsp; &nbsp;-&gt; MASTER_LOG_POS=228;</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">启动复制进程<br>mysql&gt; start slave;</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">至此配置基本完成，在主库解开table的锁定<br>mysql&gt; unlock tables;</p>
<p style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">配置全部完成，测试数据复制。</p>
<img src ="http://www.cnitblog.com/guhaiyun/aggbug/41612.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/guhaiyun/" target="_blank">Henry</a> 2008-03-28 10:57 <a href="http://www.cnitblog.com/guhaiyun/archive/2008/03/28/41612.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>