打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
mysql 主从同步配置

mysql 主从同步配置

2012-02-15

一、环境

master:192.168.124.51

MYSQL版本:5.1.48-community-log

slave: 192.168.124.52

MYSQL版本:5.1.48-community-log

 

二、主从数据库

将主机上现有的数据库备份,然后在从机上建立同名数据库并还原。

(这次做的是51上的两个数据库database1和database2)

 

三、master和 slave上的相关配置
1.修改master上的配置文件my.cnf。

在[mysqld]下添加如下字段:

server-id=1

log-bin=master-binlog

binlog-do-db=database1          //需要同步的数据库

binlog-do-db=database2

binlog-ignore-db=mysql                     //被忽略的数据库

 

在master上位slave添加一个同步账号

grant replication slave on *.* to http://www.360doc.com/mailto:'slave'@'192.168.124.52' identified by ‘slave’;

                                                                          //在slave上登陆成功

重启master的mysql服务:

service mysql restart;

 

用show master status命令查看日志情况

mysql> show master status\G;

 

*************************** 1. row ***************************

File:master-binlog.000027

Position: 3151

Binlog_Do_DB: database1,database2

Binlog_Ignore_DB:

1 row in set (0.00 sec)

 

2.修改slave上的配置文件my.cnf。

在[mysqld]下添加如下字段:

server-id=2

master-host=192.168.124.51

master-user= slave

master-password= slave

master-port=3306

master-connect-retry=60

replicate-do-db=database1     //同步的数据库

replicate-do-db=database2

replicate-ignore-db=mysql  //被忽略的数据库

 

重启slave的mysql服务:

service mysql restart;

 

在进入slave机中的mysql。

mysql>start slave;

mysql>show slave status\G;

 

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.124.51

                  Master_User: AffairLog

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: master-binlog.000027

          Read_Master_Log_Pos: 3151

               Relay_Log_File: localhost-relay-bin.000379

                Relay_Log_Pos: 245

        Relay_Master_Log_File:master-binlog.000027

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: database1,database2

          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: 3151

              Relay_Log_Space: 543

              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:

1 row in set (0.00 sec)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
MySQL配置主主及主从备份
mysql主从双向同步复制
MySQL主从配置详解
主从库配置感念
Linux下mysql主从同步备份master
阿里云RDS与ECS服务器数据库做主从 [精]
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服