一.Mysql主从复制配置
在我之前的文章四·安装mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基于Centos7源码安装 和 九.mysql数据库多实例安装mysqld_multi [start,stop,report] 两篇文章写到了单太服务器多实例的安装,本篇文章是关于主从复制的配置。本次把mysql3306作为主Master,mysql3307和mysql3308作为Slave
一.启动3台mysql服务器
[mysql@iZ25ufmpy4sZ ~]$ mysqld_multi start
[mysql@iZ25ufmpy4sZ ~]$ mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
二.登录Master主服务器mysql3306
[mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3306.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
三.在Master主服务器mysql3306上建立账户并授权Slave
mysql> grant replication slave on *.* to 'mysqlsync'@'%' identified by 'mysqlsync';
Query OK, rows affected, warning (0.00 sec)
mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| mysql3306_bin.000006 | 442 | | | |
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
四.登录Slave从服务器mysql3307或mysql3308
[mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3307.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
五.配置Slave从服务器mysql3307或mysql3308
mysql> change master to master_host='127.0.0.1',master_user='mysqlsync',master_password='mysqlsync',master_log_file='mysql3306_bin.000006',master_log_pos=;
Query OK, rows affected, warnings (0.05 sec) mysql> start slave;
Query OK, rows affected (0.03 sec) mysql>
六.在Slave从服务器上查看slave状态
mysql> mysql> show slave status;
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version |
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
| Waiting for master to send event | 127.0.0.1 | mysqlsync | | | mysql3306_bin. | | iZ25ufmpy4sZ-relay-bin. | | mysql3306_bin. | Yes | Yes | | | | | | | | | | | | None | | | No | | | | | | | No | | | | | | | 526196c9-dbe6-11e6-aa52-00163e0066e2 | /home/mysql/mysql3307/data/master.info | | NULL | Slave has read all relay log; waiting for more updates | | | | | | | | | | | | |
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
row in set (0.00 sec)
七.主从服务器配置测试
在Master主服务器上新建一个database,则Slave从服务器上应该也能够查询到,如下
---------------一下为主服务器 [mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3306.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database test;
Query OK, row affected (0.00 sec) mysql> --------------从服务器
[mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3307.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.15-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql>
问题:1.This operation cannot be performed with a running slave io thread; run STOP SLAV
这是由于我在还没有停止slave进程的时候,又执行start slave。故要先运行stop slave,
一.Mysql主从复制配置的更多相关文章
- MYSQL主从复制配置(整理)
MYSQL主从原理及过程 原理 Mysql的 Replication 是一个异步的复制过程(mysql5.1.7以上版本分为异步复制和半同步两种模式),从一个 Mysql instace(我们称之为 ...
- mysql主从复制配置
使用mysql主从复制的好处有: 1.采用主从服务器这种架构,稳定性得以提升.如果主服务器发生故障,我们可以使用从服务器来提供服务. 2.在主从服务器上分开处理用户的请求,可以提升数据处理效率. 3. ...
- Mysql学习总结(14)——Mysql主从复制配置
mysql主从复制 怎么安装mysql数据库,这里不说了,只说它的主从复制,步骤如下: 1.主从服务器分别作以下操作: 1.1.版本一致 1.2.初始化表,并在后台启动mysql 1.3. ...
- Linux 笔记 - 第二十三章 MySQL 主从复制配置
一.前言 MySQL Replication,也被称为主从复制.AB 复制.简单来说就是 A 和 B 两台服务器做主从后,在 A 服务器上写入数据,B 服务器上也会跟着写入输入,两者之间的数据是实时同 ...
- windows10 mysql主从复制配置
注意:mysql主从复制,主从版本要一致! 生手永远在学习的路上,为了学习mysql主从复制,实现读写分离,于是在本地安装多个mysql实例来进行验证. 也因此有了下面的笔记,一来自我总结一下经验,二 ...
- linux mysql主从复制配置
1.设置主库master的servie-id值并且开启bin-log功能参数vi /etc/my.cnf修改my.cnf的参数:[mysqld]server-id=1 //每一个库的server-id ...
- mysql主从复制配置(精简版)
一.首先准备两台服务器,虚拟机即可,以笔者为例:master:192.168.1.105 slave:192.168.1.106 二.保证两台虚拟机能相互ping通,先把防火墙关闭:service i ...
- MySQL主从复制配置(Docker容器内配置)
主从工作原理: 配置介绍: MASTER:172.17.0.2 SLAVE:172.17.0.3 MASTER内数据库: 仅仅同步以上两个库(在configerdata库中创建了wu2表) SLAVE ...
- mysql 主从复制配置
环境:已经在centos下安装好mysql,安装参考:http://www.cnblogs.com/bookwed/p/5896619.html,安装好主数据库后,可以克隆一份,注意修改ip等. 19 ...
随机推荐
- 1.http请求编程-->基础原理
一.技术分析 打开网页,不管我们请求的是静态资源还是动态资源,IIS都会根据ISAPI(微软和Process软件公司联合提出的Web服务器上的API标准)这一标准,将请求的文件根据文件后缀名的不同,转 ...
- HTTP中的响应协议及302、304的含义
响应协议 HTTP/1.1 200 OK:响应协议为HTTP1.1,状态码为200,表示请求成功,OK是对状态码的解释: Server: Apache-Coyote/1.1:服务器的版本信息: Con ...
- ReentrantReadWriteLock简介
对象的方法中一旦加入synchronized修饰,则任何时刻只能有一个线程访问synchronized修饰的方法.假设有个数据对象拥有写方法与读方法,多线程环境中要想保证数据的安全,需对该对象的读写方 ...
- ugui之圆角矩形头像实现
这个是参考大神的修改了一下渲染方式实现的,可以去查看原帖的,原贴是圆形头像,原理讲的非常详细 点击这里 我写的这个只支持正方形图片,效果是酱紫的~ 一共三个代码,还需要两个代码,原帖里都有的,我只是修 ...
- Tomcat Post请求大小限制
理论上讲,POST是没有大小限制的.HTTP协议规范也没有进行大小限制,起限制作用的是服务器的处理程序的处理能力. 如:在Tomcat下取消POST大小的限制(Tomcat默认2M): 打开tomca ...
- php查找字符串中第一个非0的位置截取
$str = '00000000000000000000000000000000000000001234506'; $preg = '/[0]*/'; $result = preg_replace($ ...
- layui-学习01-基本api
全局配置 layui.config({ dir: '/res/layui/', //layui.js 所在路径(注意,如果是script单独引入layui.js,无需设定该参数.),一般情况下可以无视 ...
- iview中事件获取自定义参数
前提:页面渲染多个cascaer组件,根据不同cascader组件选中的值,加载不同内容 解决:此时需要解决的问题是,在on-change事件中返回index索引使用如下格式: <Cascade ...
- 用 State Pattern 来实现一个简单的 状态机
首先要理解 State Pattern 模式. http://www.dofactory.com/net/state-design-pattern Definition Allow an object ...
- ArcGIS for JavaScript 关于路径开发的一些记录(三)
最近被一个bug困扰了两天~ 我新发布了一个NAserver(路径分析服务),但是放在之前的代码里面发现不能生成路径.经过我的调试发现并没有代码并没有报错,并且能够返回所生成路径的Graphic la ...