• mysql 5.7.10 下互为主备配置


    mysql安装方法这里就不在介绍,网上有很多教程

    环境介绍:

    A主机: win2008_x64+mysql5.7.10 64位,ip192.168.7.180

    B主机: win2008_x64+mysql5.7.10 64位,ip192.168.7.181

    1、首先配置my.ini文件,两台主机都需要配置(一般在mysql安装的目录下面)

    A主机:my.ini,[mysqld]节点下添加如下信息

    log-bin=mysql-bin 
    server-id=181

    B主机:my.ini,[mysqld]节点下添加如下信息

    log-bin=mysql-bin 
    server-id=180

    添加如上配置后都需要重起两台主机的mysql服务。

    2、创建Replication用户

    A主机上执行如下命令:

    create user 'repl'@'%' identified by '12345678';

    GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

    grant replication client,replication slave on *.* to 'repl'@'192.168.7.181' identified by '12345678';

    B主机上执行如下命令:

    create user 'repl'@'%' identified by '12345678';

    GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
    grant replication client,replication slave on *.* to 'repl'@'192.168.7.180' identified by '12345678'

    3、查看两台主机的mysql bin log位置

    首先将两台主机mysql中的表锁定

    FLUSH TABLES WITH READ LOCK;
    FLUSH TABLES WITH READ LOCK; 代表锁定表,禁止所有操作。防止bin log位置发生变化。
    查看A主机bin log位置
    SHOW MASTER STATUS;
    A主机结果


    查看B主机的bin log位置
    SHOW MASTER STATUS;
    B主机结果

    记录下A主机结果,和B主机结果
    然后再解除两台主机mysql table的锁定
    Unlock Tables;

    4、开始设置 Slave Replication

    A主机执行如下命令:

    STOP SLAVE;
    CHANGE MASTER TO MASTER_HOST = '192.168.7.181', MASTER_USER = 'repl', 
    MASTER_PASSWORD = '12345678', MASTER_LOG_FILE = 'mysql-bin.000001',
     MASTER_LOG_POS = 467; 
    START SLAVE;

    B主机执行如下命令:

    STOP SLAVE;
    CHANGE MASTER TO MASTER_HOST = '192.168.7.180', MASTER_USER = 'repl', 
    MASTER_PASSWORD = '12345678', MASTER_LOG_FILE = 'mysql-bin.000001',
     MASTER_LOG_POS = 315; 
    START SLAVE;

    5、查看两台主机是否设置成功

    Show Slave Status;

    如果两台主机Slave_IO_Running 和Slave_SQL_Running都为YES代表设置成功。可以进行数据库操作了

     
  • 相关阅读:
    BZOJ4237:稻草人
    BZOJ4009:[HNOI2015]接水果(整体二分版)
    BZOJ3745:[COCI2015]Norma
    BZOJ3110:[ZJOI2013]K大数查询(整体二分版)
    BZOJ2716:[Violet 3]天使玩偶
    BZOJ2527:[POI2011]Meteors
    BZOJ4170:极光
    BZOJ1901:Dynamic Rankings
    Python基础终极实战 基于C/S架构的仿优酷项目
    大白话五种IO模型
  • 原文地址:https://www.cnblogs.com/lvlv/p/5156869.html
Copyright © 2020-2023  润新知