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

    4 MySQL 5.7 高可用

    4 MySQL 5.7 高可用

    4 MySQL 5.7 高可用
    https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-howto.html
    GTID(GlobalTransaction ID)是对于一个已提交事务的编号,并且是一个全局唯一的编号。GTID实际上是由UUID+TID组成的。其中UUID是一个MySQL实例的唯一标识。TID代表了该实例上已经提交的事务数量,并且随着事务提交单调递增。

    设置gtid模式,在my.cnf里面的mysqld选项卡里面设置,设置完后,重启mysql服务生效:

    [mysqld]
    gtid_mode=ON
    log-slave-updates=ON
    enforce-gtid-consistency=ON

    mysql> change master to
    master_host=‘主库IP',
    master_port=主库端口,
    master_user='repl',
    master_password=‘repl密码',
    master_auto_position=1;
    mysql> start slave;

    PS:其中这里有差别,以前非gtid的是用master_log_file='mysql-bin.000009',master_log_pos=154;而gtid就采用了master_auto_positon=1;来自动同步主库的binlog了。
    查看从库复制状态,是双YES,而且Seconds_Behind_Master: 0:
    Tell the slave to use the master with GTID based transactions as the replication data source, and to use GTID-based auto-positioning rather than file-based positioning. Issue a CHANGE MASTER TO statement on the slave, including the MASTER_AUTO_POSITION option in the statement to tell the slave that the master's transactions are identified by GTIDs.

    查看备机信息
    1.主库show slave hosts;

    1. SELECT * FROM information_schema.PROCESSLIST WHERE COMMAND = 'Binlog Dump';
      查看同步状态
      1.Show slave statusG
    2. SELECT SERVICE_STATE FROM performance_schema.replication_connection_status;

    搭建级联备库

    1. 需设置log_slave_updates=1,使备库生成binlog
    2. 备份数据库并通过备份建立新数据库
    3. 新数据库与备库同步
    4. 新数据库改为与主库同步
      reset slave;
      change master to
      master_host=‘主库IP',
      master_port=主库端口,
      master_user='repl',
      master_password=‘repl密码',
      master_auto_position=1;

    5. su - mysql
      2.登录默认(3306)端口的实例
      source .profile
      mysql –uroot –p –h127.0.0.1 –P3306
      3.登录3307端口的实例
      source .p3307
      mysql –uroot –p –h127.0.0.1 –P3307

    知识点整理:
    1、.mysql_history文件记录mysql用户执行的命令,存在安全隐患,需要进行软连接处理。lns -l /dev/null $HOME/.mysql_history
    2、mysql 如何搭建半同步和异步备库。
    3、mysql环境安装。注意修改/relay_log文件夹的属主,VIP配置。

  • 相关阅读:
    【简单算法】27.验证二叉搜索树
    【简单算法】26. 二叉树的最大深度
    【简单算法】25. 环形链表
    pandas 数据处理
    主成分分析 PCA
    hive 导出数据到本地
    深度学习的优化方法 总结
    ALS算法 (面试准备)
    Bagging和Boosting的区别(面试准备)
    ROC 曲线,以及AUC计算方式
  • 原文地址:https://www.cnblogs.com/chenshengqun/p/9078012.html
Copyright © 2011-2022 走看看