zoukankan      html  css  js  c++  java
  • mysql 简单主从

    主服务器master

    [root@localhost ~]# vim /etc/my.cnf
    [mysqld]
    log-bin=mysql-bin   #必须开启log-bin
    server-id=129       #服务器ID
    

      

    从服务器slave

    [root@localhost ~]# vim /etc/my.cnf
    [mysqld]
    log-bin=mysql-bin   #开启log-bin(可选)
    server-id=129       #服务器ID
    [root@localhost ~]# systemctl restart mysqld  #主从服务器
     
    
    mysql> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by '123456';  #主服务器授权账号
    mysql> show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000001 |      439 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    1 row in set (0.00 sec)
    

      

    #查看master状态
    mysql> stop slave;
    mysql>change master to 
    master_host='192.168.100.129',master_user='mysync',master_password='123456', 
    master_log_file='mysql-bin.000004',master_log_pos=308;
    mysql> stop slave;
    mysql> show slave statusG  #查看slave状态
       Slave_IO_Running: Yes  #必须为Yes
       Slave_SQL_Running: Yes #必须为Yes
    
    如果在master 也配置 slave 架构就成了主主模式 需要注意数据一致性的问题
    

      

    虚拟机克隆需要重新生成auto.cnf

    [root@localhost ~]# mv /var/lib/mysql/auto.cnf /tmp
    [root@localhost ~]# systemctl restart mysqld
    

      

  • 相关阅读:
    数据库系统概念PDF下载
    数据库系统基础教程PDF下载
    推荐系统技术、评估及高效算法PDF下载
    系统分析与设计方法PDF下载
    像计算机科学家一样思考pythonPDF下载
    学习bashPDF下载
    厚书读薄丨《Vim实用技巧》第一部分 模式
    Code Server 是什么?
    ubuntu磁盘分区
    Linux自学之旅-基础命令(umask默认权限)
  • 原文地址:https://www.cnblogs.com/37yan/p/6879372.html
Copyright © 2011-2022 走看看