zoukankan      html  css  js  c++  java
  • MySQL 主从复制

    Master: 192.186.40.130
    Slave :   192.186.40.131

    以下是在Master库进行的操作

    # 在Master上启用bin log,设置唯一Server ID
    shell> vi /etc/my.cnf
    [mysqld]
    log-bin=mysql-bin
    server-id       = 1

    # 建立复制用的user
    mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'repl';
    mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

    # 锁定Master,并记录日志的file和position信息

    mysql> FLUSH TABLES WITH READ LOCK;
    mysql> show master status;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000020 |      696 |              |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.03 sec)

     

    # Master库的数据快照
    shell> mysqldump --all-databases --lock-all-tables > dbdump.db

    # 释放锁定mysql> UNLOCK TABLES;

    以下是在Master库进行的操作

    # 在Slave设置唯一Server ID
    shell> vi /etc/my.cnf
    [mysqld]
    server-id       = 101

    # 以--skip-slave-start 方式启动Slave
    shell> mysqld_safe --skip-slave-start &

    # 导入快照数据
    shell> mysql < dbdump.dump

    # 配置关于Master的信息
    mysql> change master to
    -> master_host='192.168.40.130',
    -> master_user='repl',
    -> master_password='repl',
    -> master_log_file='mysql-bin.000020',
    -> master_log_pos=696 ;


    # 启动Slave进程
    mysql> START SLAVE;
  • 相关阅读:
    [视频监控]用状态机图展示Layout切换关系
    初次打开mysql5.6后
    eclipse 项目乱码
    java servlet 中遇到的编码问题
    解决HttpServletResponse输出的中文乱码问题
    The first day of my Blog
    最大子段和
    LOI 54 成立一周年纪(zuo)念(si)
    水题 逆序对 NOIP 2013 火柴排队
    搜索 由浅入深 之一 水题
  • 原文地址:https://www.cnblogs.com/wait4friend/p/2334562.html
Copyright © 2011-2022 走看看