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;
  • 相关阅读:
    输入输出重定向
    进程管理
    普通变量_环境变量_环境变量配置文件
    高级文件操作命令_文件查找
    软件包管理_rpm命令管理_yum工具管理_文件归档压缩_源码包管理
    用户管理_组管理_设置主机名_UGO_文件高级权限_ACL权限
    字符串是否包含中文
    SQL 优化
    JS数组
    RedisUtil 工具类
  • 原文地址:https://www.cnblogs.com/wait4friend/p/2334562.html
Copyright © 2011-2022 走看看