在我之前的文章四·安装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主从复制配置的更多相关文章

  1. MYSQL主从复制配置(整理)

    MYSQL主从原理及过程 原理 Mysql的 Replication 是一个异步的复制过程(mysql5.1.7以上版本分为异步复制和半同步两种模式),从一个 Mysql instace(我们称之为 ...

  2. mysql主从复制配置

    使用mysql主从复制的好处有: 1.采用主从服务器这种架构,稳定性得以提升.如果主服务器发生故障,我们可以使用从服务器来提供服务. 2.在主从服务器上分开处理用户的请求,可以提升数据处理效率. 3. ...

  3. Mysql学习总结(14)——Mysql主从复制配置

    mysql主从复制 怎么安装mysql数据库,这里不说了,只说它的主从复制,步骤如下: 1.主从服务器分别作以下操作:   1.1.版本一致   1.2.初始化表,并在后台启动mysql   1.3. ...

  4. Linux 笔记 - 第二十三章 MySQL 主从复制配置

    一.前言 MySQL Replication,也被称为主从复制.AB 复制.简单来说就是 A 和 B 两台服务器做主从后,在 A 服务器上写入数据,B 服务器上也会跟着写入输入,两者之间的数据是实时同 ...

  5. windows10 mysql主从复制配置

    注意:mysql主从复制,主从版本要一致! 生手永远在学习的路上,为了学习mysql主从复制,实现读写分离,于是在本地安装多个mysql实例来进行验证. 也因此有了下面的笔记,一来自我总结一下经验,二 ...

  6. linux mysql主从复制配置

    1.设置主库master的servie-id值并且开启bin-log功能参数vi /etc/my.cnf修改my.cnf的参数:[mysqld]server-id=1 //每一个库的server-id ...

  7. mysql主从复制配置(精简版)

    一.首先准备两台服务器,虚拟机即可,以笔者为例:master:192.168.1.105 slave:192.168.1.106 二.保证两台虚拟机能相互ping通,先把防火墙关闭:service i ...

  8. MySQL主从复制配置(Docker容器内配置)

    主从工作原理: 配置介绍: MASTER:172.17.0.2 SLAVE:172.17.0.3 MASTER内数据库: 仅仅同步以上两个库(在configerdata库中创建了wu2表) SLAVE ...

  9. mysql 主从复制配置

    环境:已经在centos下安装好mysql,安装参考:http://www.cnblogs.com/bookwed/p/5896619.html,安装好主数据库后,可以克隆一份,注意修改ip等. 19 ...

随机推荐

  1. java 配置在.properties文件中的常量

    不让用常量类,那就用.properties文件配置,放在根目录. import java.util.HashMap; import java.util.Iterator; import java.ut ...

  2. jQuery 整体架构

    不同于 jQuery 代码各个模块细节实现的晦涩难懂,jQuery 整体框架的结构十分清晰,按代码行文大致分为如上图所示的模块. 初看 jQuery 源码可能很容易一头雾水,因为 9000 行的代码感 ...

  3. Spring Cloud实战之初级入门(四)— 利用Hystrix实现服务熔断与服务监控

    目录 1.环境介绍 2.服务监控 2.1 加入依赖 2.2 修改配置文件 2.3 修改启动文件 2.4 监控服务 2.5 小结 3. 利用hystrix实现消费服务熔断 3.1 加入服务熔断 3.2 ...

  4. 从服务器下载文件 DownloadServlet()

    .html代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  5. HDU 2167 Pebbles 状态压缩dp

    Pebbles Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  6. docker 镜像构建上下文理解

    原文 写得贼好,特别鸣谢,哈哈 如果注意,会看到 docker build 命令最后有一个 . . . 表示当前目录,而 Dockerfile就在当前目录,因此不少初学者以为这个路径是在指定 Dock ...

  7. flask之wtforms 表单验证(一)

    一  安装wtforms pip install wtforms 二  导入相关模块及对象 from wtforms import Form, widgets, validators from wtf ...

  8. zookeeper学习实践1-实现分布式锁

    引言 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提 ...

  9. ECMA6所有知识点大概笔记

    ECMAScript和JavaScript的关系是,前者是后者的规格,后者是前者的一种实现 初学者一开始学习JavaScript,其实就是在学3.0版的语法. -------------------- ...

  10. Recursive sum in parent-child hierarchy T-SQL

    ---树形(父子关系类)分级类统计(父子统计) --涂聚文 2014-08-14 drop table BookKindList create table BookKindList ( BookKin ...