zoukankan      html  css  js  c++  java
  • MYSQL 主主复制

    主主数据库数据结构一致。

    主一数据库IP:192.168.31.131

    主二数据库IP:192.168.31.221

    步骤:

    第一步:配置数据库的二进制日志,以及要传输的数据库(my.ini 要在 [mysqld] 下)。

    主一数据库

    [mysqld]

    log-bin="D:/Mysql/log/binlog"

    expire_logs_days = 10
    max_binlog_size = 100M

    server-id = 1
    auto-increment-increment = 2
    auto-increment-offset = 1 --这两行配置防止主键冲突
    binlog-do-db = zws --传输数据库 zws
    binlog-ignore-db = mysql -- 忽略数据库 mysql

    主二数据库

    [mysqld]

    log-bin="D:/Mysql/log/binlog"

    expire_logs_days = 10
    max_binlog_size = 100M

    server-id = 2
    auto-increment-increment = 2
    auto-increment-offset = 2 --这两行配置防止主键冲突
    binlog-do-db = zws --传输数据库 zws
    binlog-ignore-db = mysql -- 忽略数据库 mysql


    第二步:配置数据库传输用户(主一主二都要执行)

    mysql>grant replication slave on *.* to repl@'%' identified by '123456'; -- 用户名为repl 密码为123456

    第三步:查看数据库的状态(主一主二都要执行)

    mysql>show master status \G;

    其中File和Position要记下它们的值,后面配置从数据库的时候会用到。

    第四步:配置slave 信息

    主二数据库

    mysql> change master to
    -> master_host='192.168.31.131',
    -> master_user='repl',
    -> master_password='123456',
    -> master_log_file='binlog.000003', -- 第三步的 File
    -> master_log_pos=120; --第三步的 Position

    主一数据库
    mysql> change master to
    -> master_host='192.168.31.221',
    -> master_user='repl',
    -> master_password='123456',
    -> master_log_file='binlog.000002', -- 第三步的 File
    -> master_log_pos=442; --第三步的 Position


    (主一主二都要执行)

    mysql>start slave;

    查看状态,如果没有报错信息,即可进行测试。

    mysql>show slave status \G;

    文:http://www.ylsjwang.com/dianshiju/24.html

  • 相关阅读:
    Leetcode Spiral Matrix
    Leetcode Sqrt(x)
    Leetcode Pow(x,n)
    Leetcode Rotate Image
    Leetcode Multiply Strings
    Leetcode Length of Last Word
    Topcoder SRM 626 DIV2 SumOfPower
    Topcoder SRM 626 DIV2 FixedDiceGameDiv2
    Leetcode Largest Rectangle in Histogram
    Leetcode Set Matrix Zeroes
  • 原文地址:https://www.cnblogs.com/sjc9009/p/9167805.html
Copyright © 2011-2022 走看看