msyql 主从配置

参考:http://www.cnblogs.com/suchshow/articles/2282741.html

场景描述:

基于lnmp.org 的 lnmp包,mysql版本5.5.28

主数据库服务器:192.168.2.103
从数据库服务器:192.168.2.104

开始!!!!

#首先关闭防火墙,或者写规则
#这边为了方便,就关闭防火墙
#如果不关闭或者没有写相应的规则,那么 同步时 参数 Slave_IO_Running 将会 显示 connecting 链接中 而不是 yes

service iptables stop
# 192.168.2.103

/etc/init.d/mysql start #启动mysql

mysql -uroot -p #登录

#授权
mysql> GRANT REPLICATION SLAVE ON *.* to 'username'@'192.168.2.104' identified by 'password';

mysql> show master status G
*************************** 1. row ***************************
            File: mysql-bin.000008
        Position: 927
    Binlog_Do_DB: 
Binlog_Ignore_DB: 
1 row in set (0.00 sec)

记录下  File和Position的值 等下有用
# 192.168.2.104

vim /etc/my.cnf    #编辑mysql配置文件

#将 server-id = 1修改为 server-id = 10,并确保这个ID没有被别的MySQL服务所使用。

#启动并登陆

mysql> change master to
master_host=’192.168.2.104’,
master_user=’username’,
master_password=’password’,
master_log_file=’mysql-bin.000008’,  # 刚刚记录的值
master_log_pos=927;                        # 刚刚记录的值

正确执行后启动Slave同步进程

mysql> start slave;
 

主从同步检查

mysql> show slave statusG

show slave status 结果

mysql> show slave status G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.2.103
                  Master_User: mysql
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000008
          Read_Master_Log_Pos: 107
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000008
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          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: 107
              Relay_Log_Space: 413
              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: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1
1 row in set (0.00 sec)

如果标红2行为YES的话,那么基本上就成功了。

然后就测试是否成功!

OK!!同步成功。

原文地址:https://www.cnblogs.com/pangou/p/3203197.html