zoukankan      html  css  js  c++  java
  • mysql主主同步方案

    第一台机器

    vim /etc/my.cnf

     插入内容:

    server-id=1
    log-bin=mysql-binlog
    log-slave-updates=true
    max_binlog_size=1024M
    auto_increment_offset = 1
    auto_increment_increment = 2

    replicate-ignore-db = information_schema
    replicate-ignore-db = performance_schema
    replicate-ignore-db = test
    replicate-ignore-db = mys

    max_connections = 3000
    max_connect_errors = 30

    skip-character-set-client-handshake
    init-connect='SET NAMES utf8'
    character-set-server=utf8
    wait_timeout=1800
    interactive_timeout=1800
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    relay-log=relay-log-bin
    relay-log-index=slave-relay-bin.index

    systemctl start mariadb    //重启mariadb

    mysql -uroot -p000000      //连接mysql

     grant replication slave on *.* to 'repl'@'192.168.96.4' identified by '123456';

    flush privileges;    //重新声明

    show master status;

     第二台机器:

    vim /etc/my.cnf

    插入内容;

    server-id = 2
    log-bin=mysql-binlog
    log-slave-updates=true
    max_binlog_size=1024M
    auto_increment_offset = 2
    auto_increment_increment = 2
    replicate-ignore-db = information_schema
    replicate-ignore-db = performance_schema
    replicate-ignore-db = test
    replicate-ignore-db = mysql

    max_connections = 3000
    max_connect_errors = 30

    skip-character-set-client-handshake
    init-connect='SET NAMES utf8'
    character-set-server=utf8
    wait_timeout=1800
    interactive_timeout=1800
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    relay-log=relay-log-bin
    relay-log-index=slave-relay-bin.index

    systemctl start mariadb    //重启mariadb

    mysql -uroot -p000000      //连接mysql

     grant replication slave on *.* to 'repl'@'192.168.96.5' identified by '123456';

    flush privileges;    //重新声明

    show master status;

    特殊参数说明:

    log-slave-updates = true     #将复制事件写入binlog,一台服务器既做主库又做从库此选项必须要开启

    masterA自增长ID

    auto_increment_offset = 1
    auto_increment_increment = 2 #奇数ID
    masterB自增加ID
    auto_increment_offset = 2
    auto_increment_increment = 2 #偶数ID

    第一台机器:

    stop slave;

    change master to master_host='192.168.96.4',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-binlog.000001',master_log_pos=595;

     start slave;

    show slave statusG;

    第二台机器;

    stop slave;

    change master to master_host='192.168.96.5',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-binlog.000001',master_log_pos=483;

     start slave;

    show slave statusG;

    第一台机器;

    create database test01;

    第二台机器:

    show databases;

    第二台机器:

    create database test02;

    第一台机器:

    show databases;

  • 相关阅读:
    linux删除/var/log/下面所有日志 如何重新记录日志
    DIV里的内容自动换行
    it冲突:commit your changes or stash them before you can merge. 解决办法
    git切换到远程分支
    【异常】warning: refname 'feature1.3.0' is ambiguous.导致git merge失败
    在此篇文章中,我们将用 15 分钟对 PHP v7.x 版本更改进行简要回顾
    input元素所有type类型及相关作用
    微信自动关闭内置浏览器页面,返回公众号窗口 WeixinJSBridge.call('closeWindow')
    css背景渐变色
    数组的forEach和map和for方法的区别
  • 原文地址:https://www.cnblogs.com/XXXX001/p/11690625.html
Copyright © 2011-2022 走看看