zoukankan      html  css  js  c++  java
  • CentOS 7 MySQL5.7 主从配置-GTID 全自动安装脚本

    快速配置MySQL -GTID 主从,只需要1分钟。你要做的就是,把下面两段代码,先在主机上运行,后在从机上运行

    当然,这里省去了MySQL的安装过程,如果你需要快速安装MySQL ,可以运行下面的全自动脚本。全自动安装mysql脚本:  https://www.cnblogs.com/ypeuee/p/13235307.html

    主库配置


    #修改配置 启动gtid sed -i -e '6a server-id = 1' /etc/my.cnf sed -i -e '7a gtid_mode=on' /etc/my.cnf sed -i -e '8a enforce_gtid_consistency=on' /etc/my.cnf sed -i -e '9a log-slave-updates=1' /etc/my.cnf sed -i -e '10a log-bin=master-bin' /etc/my.cnf sed -i -e '11a log-bin-index = master-bin.index' /etc/my.cnf sed -i -e '12a relay-log = relay-log' /etc/my.cnf sed -i -e '13a relay-log-index = relay-log.index' /etc/my.cnf sed -i -e '14a binlog_format=row' /etc/my.cnf #重启mysql systemctl restart mysqld; #登录 mysql mysql -uroot -p123456 #创建用户 grant replication slave on *.* to 'rep'@'192.168.3.%' identified by '123456'; flush privileges;
    #复制到此处

    从机配置

    #修改配置 启动gtid
    
    sed -i -e  '6a server-id = 2' /etc/my.cnf
    sed -i -e  '7a gtid_mode=on' /etc/my.cnf
    sed -i -e  '8a enforce_gtid_consistency=on' /etc/my.cnf
    sed -i -e  '9a log-slave-updates=1' /etc/my.cnf
    sed -i -e  '10a log-bin=master-bin' /etc/my.cnf
    sed -i -e  '11a log-bin-index = master-bin.index' /etc/my.cnf
    sed -i -e  '12a relay-log = relay-log' /etc/my.cnf
    sed -i -e  '13a relay-log-index = relay-log.index' /etc/my.cnf
    sed -i -e  '14a binlog_format=row' /etc/my.cnf
    
    #重启mysql
    systemctl restart mysqld;
    
    #登录 mysql 
    mysql -uroot -p123456
    
    #连接到主机
    change master to master_host='192.168.3.160',master_user='rep',master_password='123456',master_port=3306,master_auto_position=1;
    
    #等待2秒
    select sleep(2); 
     
    #启动主从
    start slave;
    
    #等待2秒
    select sleep(2); 
     
    #查看状态
    show slave status G

    #复制到此处
  • 相关阅读:
    信息领域热词分类分析03
    虚拟机Linux联网问题
    每日学习
    第七章 Centos下搭建Maven私有仓库
    第六章 Maven-profile及插件
    第五章 Maven-构建生命周期、阶段、目标
    第四章 Maven-依赖管理
    第三章 Maven-pom.xml文件
    第二章 Maven-Repository存储库
    第一章 Maven入门
  • 原文地址:https://www.cnblogs.com/ypeuee/p/13279741.html
Copyright © 2011-2022 走看看