zoukankan      html  css  js  c++  java
  • MySQL主从同步配置

    服务器:centos7

    mysql:5.6

    master mysql ip:192.168.0.150

    master slave ip:192.168.0.128

    1、修改master上的mysql的配置文件my.cnf

    [mysqld]
    #### master
    # mysql主从备份 start
    # 启动二进制日志
    log-bin=mysql-bin
    
    # 服务器唯一ID master
    server-id=150
    
    # 二进制日志自动删除的天数
    expire_logs_days=5
    # mysql主从备份 end

    2、修改slave上MySQL配置文件my.cnf

    [mysqld]
    #### slave
    # mysql主从备份 start
    # 启动二进制日志
    log-bin=mysql-bin
    
    # 服务器唯一ID slave
    server-id=128
    
    # 二进制日志自动删除的天数
    expire_logs_days=5
    # mysql主从备份 end

    3、重启Master和Slave上的MySQL

    systemctl restart mysql

    4、在master上建立帐户并授权slave

    mysql>GRANT REPLICATION SLAVE ON *.* to 'mysync'@'192.168.0.128' identified by 'foo';
    mysql>FLUSH PRIVILEGES:

    5、使用root账户登录Master查看Master状态

    mysql>show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000003 |      332 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+

    注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化。

    此时要确认slave服务器上的数据库结构与master一致,若不一致,在master上插入数据后,slave中会报错:“找不到对应的表”。

    6、配置slave服务器

    change master to master_host='192.168.0.150',master_user='mysync',master_password='foo',master_log_file='mysql-bin.000003',master_log_pos=332;

    7、启动从服务器复制功能

    start slave;

    8、使用root账户登录slave mysql,检查slave复制功能状态

    show slave statusG

    其中两项必须为yes。
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes

  • 相关阅读:
    linux下使用tar命令
    ContentType和@ResponseBody
    ActiveMQ两种模式PTP和PUB/SUB<转>
    Postgresql分表与优化
    PostgreSQL存储过程<转>
    PostgreSQL Table Partitioning<转>
    Postgresql查询表的大小
    Postgresql添加/删除触发器示例
    Android TextView 支持的HTML标签
    我只是一直很努力
  • 原文地址:https://www.cnblogs.com/xxoome/p/9850451.html
Copyright © 2011-2022 走看看