Home > Database > Mysql Tutorial > body text

配置MySQL数据库同步的实际操作步骤

WBOY
Release: 2016-06-07 16:13:42
Original
1086 people have browsed it

以下的文章主要介绍的是配置MySQL数据库同步的实际操作步骤,我们本次试验是在MySQL数据库版本 4.1.7-standard-log环境下对其进行操作 , master 端的实际操作操作系统是 redhat 9.0 , slave 端的操作系统是 redhat 7.3. 1.修改 master 端的my.cnf,增加配置参

以下的文章主要介绍的是配置MySQL数据库同步的实际操作步骤,我们本次试验是在MySQL数据库版本 4.1.7-standard-log环境下对其进行操作 , master 端的实际操作操作系统是 redhat 9.0 , slave 端的操作系统是 redhat 7.3.

1.修改 master 端的my.cnf,增加配置参数:

<ol class="dp-xml">
<li class="alt"><span><span>[MySQL(和PHP搭配之最佳组合)d]  </span></span></li>
<li><span>log-bin  </span></li>
<li class="alt">
<span class="attribute">server-id</span><span>=</span><span class="attribute-value">1</span><span> </span>
</li>
</ol>
Copy after login

2. 修改 slave 端的my.cnf,增加配置参数:

<ol class="dp-xml">
<li class="alt"><span><span>log-bin  </span></span></li>
<li>
<span class="attribute-value">master</span><span class="attribute">master-host</span><span>=master  </span>
</li>
<li class="alt">
<span class="attribute">master-user</span><span>=</span><span class="attribute-value">rep</span><span> </span>
</li>
<li>
<span class="attribute">master-password</span><span>=</span><span class="attribute-value">rep</span><span> </span>
</li>
<li class="alt">
<span class="attribute">master-port</span><span>=</span><span class="attribute-value">3306</span><span> </span>
</li>
<li>
<span class="attribute">server-id</span><span>=</span><span class="attribute-value">2</span><span> </span>
</li>
</ol>
Copy after login

以上参数都是最基本的配置,就不多解释了,解下来势初始化数据.

1.清空 master 上的所有 binlog,如果现存的 binlog有用的话,请先备份起来;接着把 master 上的所有数据文件打包,包括ibdata那些文件.

2.类似的方法清空 slave 上的所有 binlog,将 master上的数据文件压缩包拷贝到自身的数据文件目录下.

启动master,新增一个rep用户

<ol class="dp-xml"><li class="alt"><span><span>,"grant all privileges on *.* to rep@% identified by 'rep'; flush privileges; ". </span></span></li></ol>
Copy after login

启动slave,检测MySQL数据库同步是否成功.

一般情况下,不成功的原因是slave连接上master之后定位binlog失败,这就需要将双方的binlog都设置成一致,然后stop slave; start slave; 即可.


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template