zoukankan      html  css  js  c++  java
  • linux 下 mysql的 主从同步 读写分离

    Hello everyone!

    今天介绍一下 Linux 下如何实现主从同步 读写分离 <master上进行写操作,同步数据库,slave上进行读操作,可以极大的提升性能>

    这到底是啥意思呢  你可以理解为  当主库挂了 从库可以立即顶上去!作用在不同服务器上相同的库,一个服务器上库出现问题另一个快就可以立即使用!!

    ok-----begin

    首先前提工作是 准备两台虚拟机(centos7) 同时两台虚拟机上必须装有相同版本的 MySQL

    主 master
     ip:172.16.65.22
    从 slave
     ip:172.16.65.21

    两台机子都可以互相ping同 / 关闭防火墙

    然后开始写配置文件

    寻找自己的路径 vim /etc/my.cnf 编辑 添加配置如图
     
    找不见的话 执行  whereis my.cnf

    各项工作准备完毕后 在master上创建一个同步权限的账户 用来同步数据

    创建新用户

    create user 'user'@'X.X.X.X' identified by 'password'; 这条是编辑新密码 update user set authentication_string=PASSWORD('密码') where user='用户名';

    查看主库状态

     show master status;

      

    mysql> show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000002 | 5113 | | | |
    +------------------+----------+--------------+------------------+-------------------+

    最后一个点 配置从库 slave

    mysql> change master to
        -> master_host='192.168.175.22',      #ip
        -> master_user='repluser',        #用户名
        -> master_password='Root123!',    #密码
        -> master_port=3306,           #端口
        -> master_log_file='mysql-bin.000002',  
        -> master_log_pos=6326;
    Query OK, 0 rows affected, 1 warning (0.01 sec)

    最后就可以 在 从库上 看到 主库的数据  增删查改一样.

    end...

     

  • 相关阅读:
    Blank page instead of the SharePoint Central Administration site
    BizTalk 2010 BAM Configure
    Use ODBA with Visio 2007
    Handling SOAP Exceptions in BizTalk Orchestrations
    BizTalk与WebMethods之间的EDI交换
    Append messages in BizTalk
    FTP protocol commands
    Using Dynamic Maps in BizTalk(From CodeProject)
    Synchronous To Asynchronous Flows Without An Orchestration的简单实现
    WSE3 and "Action for ultimate recipient is required but not present in the message."
  • 原文地址:https://www.cnblogs.com/xiaolizikj/p/11752696.html
Copyright © 2011-2022 走看看