zoukankan      html  css  js  c++  java
  • mysql 配置主从复制

    简介:mysql 实现主从复制的原理 通过主数据库binlog文件重做实现数据同步(尽量保证mysql版本相同)

    1. 准备两台mysql服务

      ip1:192.168.44.3 主服务器

      ip2:192.168.44.5 从服务器

    主服务器

    2. 配置my.cnf

      vim /etc/my.conf

      添加配置:

        [mysqld]

        log-bin=mysql-bin

        server-id=1

    3.设置一个复制使用的账号并且赋予replication slave 权限

      1.创建账号 create user 'username'@'localhost' identified by 'password'

      2.赋予权限 grant replication slave on *.* to 'username'@'localhost'  (localhost->ip地址 可以对ip段设置 例如: 192.168.44.%)

    从服务器

    4. 配置从my.cnf

      vim /etc/my.conf

      添加配置:

        server-id = 2 (服务id不可重复)

        log_slave_updates = 1 (三级同步必加 例子 数据库A->数据库B->数据库C 数据库B根据数据A binlog 复制 不属于数据库执行sql 不会添加binlog日志 数据库C的数据跟 AB 就不同步了)

        read_only = 1 (只读)

    5. 连接数据库,指定主数据库的ip 端口 用户

      change master to master_host='192.168.44.3',master_port=3306,master_user='username',master_password='password',master_log_file='mysql-bin.xxxxx',master_log_pos=xxxx;

      master_log_file,master_log_pos 查询

        show master status; (主节点数据库 执行) 返回结果

        file=master_log_file,position=master_log_pos 

    6.测试 在主节点任意一张表中 添加一条数据 ,检查 从库 该表 是否增加了该数据

  • 相关阅读:
    python pop()
    二年为限,看到自己的改变
    Android layout布局属性、标签属性总结大全
    js判断PC端和移动端
    JS简易模拟滚动条
    (响应式PC端媒体查询)电脑屏幕分辨率尺寸大全
    手机尺寸和平板电脑的屏幕分辨率
    【整理笔记】手机端html页面制作需要了解的东西集合
    JS获取浏览器版本号及获取IE版本提示并关闭
    CSS DIV垂直居中
  • 原文地址:https://www.cnblogs.com/MXubin/p/14268575.html
Copyright © 2011-2022 走看看