• mysql主从复制


    mysql互为主从

    主机 A

    1.下载数据库

    centos6 为mysql centos7 为mariadb
    yum -y install mariadb mariadb-server

    2.修改mysql的配置文件

    server_id=1            #后面的数字为n 但是不要重复,以免冲突
    log_bin=wendi        # 后面的名字自定义
    relay_log=wenhui   #后面的名字自定义

    3 重启mysql

    systemctl start mariadb

    4 进入mysql

    增加同步用户:
    MariaDB [(none)]> grant all on *.* to 'hh'@'%' identified by 'tom';
    MariaDB [(none)]> flush privileges; #刷新数据用户

    查看bin-log日志

    MariaDB [(none)]> show master status;

    主机 B

    1,下载mysql

    yum -y install mariadb mariadb-server

    2.修改mysql的配置文件

    server_id=2 #后面的数字为n 但是不要重复,以免冲突
    log_bin=wendi # 后面的名字自定义
    relay_log=wenhui #后面的名字自定义

    3 重启mysql

    systemctl start mariadb

    4 进入mysql

    MariaDB [(none)]> change master to master_host='192.168.177.246',master_user='hh',master_password='tom',master_log_file='wendi.000003',master_log_pos=443;
    Query OK, 0 rows affected (0.01 sec)

      这里的master_host是指主机A的ip地址,master_uesr是执行同步操作的用户名,master_password是执行同步的用户密码,master_log_file是主机A的bin-log日志,master_log_pos是从bin-log日志开始同步的位置

    5 开启同步日志

    MariaDB [(none)]> start slave;

    6 查看是否同步

    MariaDB [(none)]> show slave status G;
    *************************** 1. row ***************************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 192.168.177.246
    Master_User: hh
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: wendi.000003
    Read_Master_Log_Pos: 443
    Relay_Log_File: wendhui.000002
    Relay_Log_Pos: 525
    Relay_Master_Log_File: wendi.000003
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes

    出现双yes 代表成功。
    如果出现错误请检查防火墙是否关闭。或者用户名或者密码是否错误等等。

    7.B主机上也要增加同步用户:

    MariaDB [(none)]> grant all on *.* to 'hh'@'%' identified by 'tom';
    MariaDB [(none)]> flush privileges; #刷新数据用户
    查看bin-log日志
    MariaDB [(none)]> show master status;

    8 A主机操作

    MariaDB [(none)]> change master to master_host='192.168.177.248',master_user='wen',master_password='wen',master_log_file='wendi.000003',master_log_pos=443;
    Query OK, 0 rows affected (0.01 sec)

    9 同步测试
    A主机或者B主机做都可以
    在A上创建一个数据库

    mysql> create database test2;

    在B主机上能看到就可以了! 成功!!!!

  • 相关阅读:
    没有可持续集成的日子里
    Apache Avro 与 Thrift 比较
    CruiseControl.NET以及使用
    不靠谱产品经理的特征
    Hadoop 新 MapReduce 框架 Yarn 详解
    Storm On YARN
    iOS开发资源:推送通知相关开源项目--PushSharp、APNS-PHP以及Pyapns等
    Swift REPL入门介绍
    学习Swift,一定不能错过的10大开源项目!
    iOS8 Size Classes的理解与使用
  • 原文地址:https://www.cnblogs.com/wendyluo/p/13136740.html
Copyright © 2020-2023  润新知