一.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 ...
随机推荐
- Java入门系列-21-多线程
什么是线程 在操作系统中,一个应用程序的执行实例就是进程,进程有独立的内存空间和系统资源,在任务管理器中可以看到进程. 线程是CPU调度和分派的基本单位,也是进程中执行运算的最小单位,可完成一个独立的 ...
- C# [method Modifiers] abstract virtual override new
abstract :表示方法是抽象方法,在子类中必须重写.抽象方法所在的类必须是抽象类,即用abstract modifiers:virtual:表示此方法是virtual方法,除了在子类中可以重写外 ...
- WPF binding<一> Data Binding在WPF中的地位
在代码中看到 <Image Source="{Binding ElementName=LBoxImages, Path=SelectedItem.Source}" /> ...
- Node.js学习笔记(二) --- CommonJs和Nodejs 中自定义模块
一. 什么是 CommonJs? JavaScript 是一个强大面向对象语言,它有很多快速高效的解释器. 然而, JavaScript标准定义的 API 是为了构建基于浏览器的应用程序.并没有制定一 ...
- redis的安全问题
1.修改redis.conf配置文件 2.重启redis服务,使其生效 3.成功登陆以后,使用auth+密码 或者在登录的时候使用-a 密码的授权方式
- dockerfile 踩坑记录
1.使用ADD/COPY命令 源文件必须和Dockfile位于同一目录下(使用绝对路径是没用的,会提示找不到你的源文件) 2.ADD命令会自动解压 3.尽量耗时且不容易变的部分放在dockerfile ...
- MySql中存储引擎MyISAM与InnoDB区别于选择
InnoDB: 支持事务处理等 不加锁读取 支持外键 支持行锁 不支持FULLTEXT类型的索引 不保存表的具体行数,扫描表来计算有多少行 DELETE 表时,是一行一行的删除 InnoDB 把数据和 ...
- pyhton基础中的要点一
1.python变量的命名规范: (1)变量必须以数字,字母,下划线的任意组合 (2)变量建议用驼峰标识,或下划线 (3)变量要有可描述性 (4)不能以数字开头 (5)不能用python的关键字 (6 ...
- cf1043F. Make It One(dp 容斥原理)
题意 题目链接 给出\(n\)个数,问最少选几个数,使他们的\(gcd = 1\) Sol 好神仙啊qwq. 首先,如果答案存在,那么最多为\(7\)(因为前\(7\)个质数乘起来\(>= 3e ...
- JavaScript 递归法排列组合二维数组2
<html> <head> <title>二维数组排列组合</title> </head> <body> <div id= ...