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

    1. MySQL主主配置过程

    在上一篇实现了主从同步的基础上,进行主主同步的配置。

    这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式

    修改配置文件

    在node19和node20都修改配置文件/etc/my.cnf

    对于node19,在[mysqld]下面添加

    auto_increment_incremet=2
    auto_increment_offset=1

    对于node20,在[mysqld]下面添加

    auto_increment_increment=2
    auto_incement_offset=2

    在MySQL中有自增长字段,在配置数据库主主同步时,需要设置自增的两个相关配置

    • auto_increment_increment 表示自增字段每次都递增的量,默认值是1,取值范围为1-65535
    • auot_increment_offset 表示自增字段从那个数开始

    修改完配置文件之后,进行服务重启systemctl restart mariadb

    node20创建复制用户并授权

    node20执行mysql -uroot -p

    # 创建复制用户和授权
    grant replication slave on *.* to 'repl'@'192.168.1.19' identified by 'liwanliang';
    # 刷新权限
    flush privileges;
    # 查看主配置日志信息
    show master status;

    node19上配置主服务器并启动从服务

    node19上执行mysql -uroot -p

    # 设置主服务器
    change master to
    mastet_host='192.168.10.20',master_user='repl',master_password='liwanliang',master_log_file='mysql-bin.000002',master_log_pos=488;
    # 启动从服务器
    start slave;
    # 查看从服务器状态
    show slave statusG;

    在node19和node20上分别创建和删除数据库进行测试

    2. MySQL主主同步配合存在的问题

    1. 配置文件中的auto_increment_increment和auto_increment_offset只能够保证主键不重复,不能够保证主键有序




  • 相关阅读:
    English,The Da Vinci Code,Chapter 1-3
    Algorithm,Ds,Binary Indexed Trees,树状数组,二分索引树
    Algorithm,Acm,RMQ
    Algorithm,Number Theory,Prime
    Algorithm,Number Theory,GCD
    English,The Da Vinci Code
    Algorithm,LCA,Tarjan,深搜+并查集,最近公共祖先
    python,keyword arguments
    Qt,QObject
    python,build in functions
  • 原文地址:https://www.cnblogs.com/liwanliangblog/p/10633275.html
Copyright © 2011-2022 走看看