Mysql 复制 配置详解, Replication with Master/Slave

来源:互联网 发布:安卓windows xp镜像img 编辑:程序博客网 时间:2024/06/10 19:44

总体流程是,

  1. A机器上配置master
  2. A机器授权给B机器
  3. B机器配置slave
具体操作:
  前提:假设A机器之前已经开启了binlog,如配置log-bin=mysql-bin等


1, A机器上配置master

#这一项,在my.cnf本就存在
server-id       = 1
#下面三项不是必须
expire_logs_days        = 10
max_binlog_size         = 100M 
binlog_format           =mixed


2, A机器授权给B机器

mysql控制台下:
grant replication slave on *.* to replication@192.168.1.15 identified by '123456';

3,B机器配置slave
#默认是1,这里改为2
server-i=2 
#设置需要从A上复制过来的库名
replicate-do-db=repdb

#以下不是必须
#设置B机上的binlog,跟A机器上的没有关系,也跟ms配置没有关系
log_bin=mysql-bin
#中继binlog
relay_log=mysql-relay-bin

change master to  master_host='192.168.1.12', master_user='replication', master_password='123456', master_log_file='mysql-bin.000001', master_log_pos=0;
这里注意的是,尽管在A上设置的binlog是mysql-bin,生成的日志是带数字后缀的;但这里不能按照省略的写法,必须跟上后缀,希望从哪个日志开始,就跟谁的日志。
slave start
slave stop
slave reset
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.122
                  Master_User: replication
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 5223825
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 5223892
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: vcread
          Replicate_Ignore_DB: 
           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: 5223747
              Relay_Log_Space: 5224125
              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)


错误处理:
如果报告:
Error reading packet from server: Could not find first log file name in binary log index file
可能是因为为做正确授权,可重启A机器,即master机器上的mysql服务以重试;不行的话,重新授权,再分别重新A的mysql和B的slave


原创粉丝点击