使用工具

MySQL数据版本:5.6.36-log、

两台云服务器(Linux系统)

首先,需要在Linux系统下安装MySQL,具体步骤可以参考这里,并且确保两台主机可以相互访问,可以直接ping一下。

配置Master

  • Linux环境下,MySQL的配置文件在/ect/my.cnf,直接打开并编辑该文件:vim /etc/my.cnf
  • [mysqld]下输入配置
log-bin=mysql-bin
server-id=2
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-do-db=rwtest

这里的server-id用于标识唯一的数据库,这里设置为2在设从库需要设置为其他值

binlog-ignore-db:表示同步的时候ignore的数据库

binlog-do-db:指定需要同步的数据库

  • 重启MySQLservice mysqld restart
  • 登录MySQL并对访问用户进行授权:Slave机器需要File权限和REPLICATION SLAVE权限,当然也可以授予全部权限。
grant file on *.* to 'root'@'%' identified by 'your password';

grant replication slave on *.* to 'root'@'%' identified by 'your password';

flush privileges;

or

grant all privileges on *.* to 'root'@'%' identified by 'your password';

flush privileges;
  • 完成后,可以查看下Master的状态:show master status
mysql> show master status;
+------------------+----------+--------------+----------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+----------------------------------+-------------------+
| mysql-bin.000001 | 2272 | rwtest | information_schema,mysql | |
+------------------+----------+--------------+----------------------------------+-------------------+
1 row in set (0.03 sec)

这里的FilePositionSlave中都要用到,Binlog_Do_DB指需要同步的数据库,Binlog_Ignore_DB指不需要同步的数据库,就是刚才配置的值。

配置Slave

  • 同样在[mysqld]下对配置文件进行编写
log-bin=mysql-bin
server-id=3
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
replicate-do-db=rwtest
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60
  • 配置完毕后同样重启一下MySQL,并进入设置其对应的Master
mysql> stop slave;  #关闭Slave
mysql> change master to master_host='Master主机IP',master_user='刚才授权的用户',master_password='your password',master_log_file='mysql-bin.000001', master_log_pos=2272; mysql> start slave; #开启Slave

master_log_filemaster_log_pos都是Master的状态值。必须对应

  • 登录slave的数据库,查看slave的状态:show slave status \G
Slave_IO_State: Waiting for master to send event
Master_Host: 你的Master主机IP
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2272
Relay_Log_File: izwz9fcvpu481xh55cegx0z-relay-bin.000002
Relay_Log_Pos: 1339
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: rwtest
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 2272
Relay_Log_Space: 1530
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: de20814f-2fb8-11e7-8f61-5254002b91a1
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.03 sec)

如果状态中含有没有报Error,则表示配置成功了。

接下来你通过可视化工具连接两个数据库,在主库中进行增删改操作,从库中也会有相应的操作,而在从库中进行此类操作对主库无效。

MySQL主从数据库配置的更多相关文章

  1. MySQL主从数据库配置与原理

    1.为什么要搭建主从数据库 (1)通过增加从库实现读写分离,提高系统负载能力 (2)将从库作为数据库备份库,实现数据热备份,为数据恢复提供机会 (3)根据业务将不同服务部署在不同机器同时又共享相同的数 ...

  2. MySQL主从数据库同步延迟问题解决(转)

    最近在做MySQL主从数据库同步测试,发现了一些问题,其中主从同步延迟问题是其中之一,下面内容是从网上找到的一些讲解,记录下来以便自己学习: MySQL的主从同步是一个很成熟的架构,优点为:①在从服务 ...

  3. mysql主从同步配置(windows环境)

    mysql主从同步配置(mysql5.5,windows环境)   A主机(作为主服务器)环境:windows8.mysql5.5 ip:192.168.1.100(自己填) B主机(作为从服务器,由 ...

  4. Docker Mysql主从同步配置搭建

    Docker Mysql主从同步配置搭建 建立目录 在虚拟机中建立目录,例如路径/home/mysql/master/data,目录结构如下: Linux中 新建文件夹命令:mkdir 文件夹名 返回 ...

  5. Mysql 主从数据库

    MYSQL主从数据库同步备份配置 一.准备 用两台服务器做测试: Master Server: 172.16.0.180/Linux/MYSQL 5.1.41 Slave Server: 172.16 ...

  6. MySQL主从备份配置实例

    转载自:https://www.cnblogs.com/ahaii/p/6307648.html MySQL主从备份配置实例 场景: 1.主服务器192.168.0.225.从服务器192.168.0 ...

  7. Windows系统环境下创建mysql主从数据库方法(双向主从复制)

    创建mysql主从数据库方法(双向主从复制) (一)Windows系统下的MySQL主从复制(单向复制) (1)环境说明: 1,Mysql版本:mysql5.7.20(主从机mysql版本必须一致) ...

  8. MySQL主从架构配置

    MySQL主从架构配置有两台MySQL数据库服务器master和slave,master为主服务器,slave为从服务器,初始状态时,master和slave中的数据信息相同,当master中的数据发 ...

  9. centos:mysql主从同步配置(2018)

    centos:mysql主从同步配置(2018) https://blog.csdn.net/liubo_2016/article/details/82379115 主服务器:10.1.1.144; ...

随机推荐

  1. spring boot 开发 ajax返回值报错

    org.thymeleaf.exceptions.TemplateInputException: Error resolving template "succeed", templ ...

  2. vue.js选择if(条件渲染)详解

    vue.js选择if(条件渲染)详解 一.总结 一句话总结: v-if <!DOCTYPE html> <html lang="en"> <head& ...

  3. 各个安卓版本 使用的 Linux Kernel Version

    Android Version |API Level |Linux Kernel in AOSP --------------------------------------------------- ...

  4. 雷林鹏分享:C# 枚举(Enum)

    C# 枚举(Enum) 枚举是一组命名整型常量.枚举类型是使用 enum 关键字声明的. C# 枚举是值数据类型.换句话说,枚举包含自己的值,且不能继承或传递继承. 声明 enum 变量 声明枚举的一 ...

  5. 2018焦作网络赛Mathematical Curse

    题意:开始有个数k,有个数组和几个运算符.遍历数组的过程中花费一个运算符和数组当前元素运算.运算符必须按顺序花费,并且最后要花费完.问得到最大结果. 用maxv[x][y]记录到第x个元素,用完了第y ...

  6. Ngnix location匹配规则

    Ngnix 站点:http://www.nginx.cn Location 匹配命令 ~ 波浪线表示执行一个正则匹配,区分大小写. ~* 表示执行一个正则匹配,不区分大小写. ^~ ^~表示普通字符匹 ...

  7. js获取表格视图所选行号的ids

    实例化数组 遍历所选行push到数组中 将数组join转换为以,分割的字符串 /*获取指定id的datagrid的表格视图的选择的ids*/ function getDataGridSelectRow ...

  8. P2048 [NOI2010]超级钢琴 (RMQ,堆)

    大意: 给定n元素序列a, 定义一个区间的权值为区间内所有元素和, 求前k大的长度在[L,R]范围内的区间的权值和. 固定右端点, 转为查询左端点最小的前缀和, 可以用RMQ O(1)查询. 要求的是 ...

  9. 『PyTorch』第五弹_深入理解autograd_中:Variable梯度探究

    查看非叶节点梯度的两种方法 在反向传播过程中非叶子节点的导数计算完之后即被清空.若想查看这些变量的梯度,有两种方法: 使用autograd.grad函数 使用hook autograd.grad和ho ...

  10. 『OpenCV3』简单图片处理

    cv2和numpy深度契合,其图片读入后就是numpy.array,只不过dtype比较不常用而已,支持全部数组方法 数组既图片 import numpy as np import cv2 img = ...