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;

  • 相关阅读:
    CSAPP DataLab
    《计算机网络自顶向下》第二章应用层,笔记总结
    计算机网络自顶向下第二章套接字编程作业
    第二章---信息的表示与处理
    python界面使用gbk编码
    python修改获取xlsx数据
    刚安装了ftp之后无法使用root访问,服务器发回了不可路由的地址。使用服务器地址代替。
    ssh_exchange_identification: read: Connection reset
    <七>对于之前的一些遗漏的地方的补充
    (六)单例模式与多线程时的安全问题以及解决办法
  • 原文地址:https://www.cnblogs.com/XXXX001/p/11690625.html
Copyright © 2011-2022 走看看