分享

mysql 主从同步配置

 日积月累-随意 2012-06-30

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)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多