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;
  • 相关阅读:
    开始准备考研了
    ubuntu安装完vbox没有无缝模式
    Terminator快捷键
    ubuntu启动慢显示waiting for network configuration
    terminal快捷键
    openstack根据软件选择实例resume
    输出数组的全排列
    给非同步的集合加锁原理。
    集合框架—ArrayList的用法
    集合框架 Map的小例子
  • 原文地址:https://www.cnblogs.com/wait4friend/p/2334562.html
Copyright © 2011-2022 走看看