Mysql主从复制搭建 与读写分离
Mysql主从复制搭建
- 准备条件
- Master-Server 配置
- 修改配置
- 重启Mysql
- 配置主从复制账户
- Slave-Server 配置
- 修改配置
- 重启Mysql
- 配置Master信息开启主从复制
- 读写分离
- Master-Server 配置
- Slave-Server 配置
准备条件
准备2台机器先安装MySQL 5.7.20
Master-Server : 192.168.0.100
Slave-Server : 192.168.0.99
Master-Server 配置
修改配置
vim /etc/my.conf
添加以下配置
log-bin=mysql-bin
binlog_format=mixed
skip-name-resolve
innodb_file_per_tableserver-id = 1
重启Mysql
/etc/init.d/mysqld restart
配置主从复制账户
[root@iZbp1ajd582c8dtiadg2ggZ bin]# /opt/bin/mysql/bin/mysql -uroot -p'password'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log MySQL Bright ThoughtCopyright (c) 2000, 2017, 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 USER 'repl'@'192.168.0.99' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.02 sec)mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.99';
Query OK, 0 rows affected (0.00 sec)mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 1457 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
Slave-Server 配置
修改配置
vim /etc/my.conf
添加以下配置
log-bin=mysql-bin
binlog_format=mixed
relay-log=relay-log
relay-log-index=relay-log.indexskip-name-resolve
innodb_file_per_tableserver-id = 2
#slave_skip_errors = 1032,1062,1064
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 2
重启Mysql
/etc/init.d/mysqld restart
配置Master信息开启主从复制
[root@iZbp1c0kqbtw5ac7nkw1pfZ bin]# /opt/bin/mysql/bin/mysql -uroot -p'password'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log MySQL Bright ThoughtCopyright (c) 2000, 2017, 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> CHANGE MASTER TO MASTER_HOST='192.168.0.100',MASTER_USER='repl',MASTER_PASSWORD='password',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=1457,MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected, 2 warnings (0.04 sec)mysql> start slave;
Query OK, 0 rows affected (0.01 sec)mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.0.100Master_User: replMaster_Port: 3306Connect_Retry: 10Master_Log_File: mysql-bin.000003Read_Master_Log_Pos: 1457Relay_Log_File: relay-log.000002Relay_Log_Pos: 320Relay_Master_Log_File: mysql-bin.000003Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 1457Relay_Log_Space: 521Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1Master_UUID: 67a9c6c4-5c14-11e9-ad77-00163e098a07Master_Info_File: /opt/data/db/mysql/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version:
1 row in set (0.00 sec)ERROR:
No query specified
读写分离
Master-Server 配置
CREATE USER 'developer'@'192.168.0.%' IDENTIFIED BY 'password';
GRANT SELECT,INSERT,UPDATE ON *.* TO 'developer'@'192.168.0.%';
show grants for developer@'192.168.0.%';
Slave-Server 配置
REVOKE INSERT, UPDATE ON *.* from 'developer'@'192.168.0.%';show grants for developer@'192.168.0.%';
Mysql主从复制搭建 与读写分离相关推荐
- mysql主从复制中间件_linux下mysql主从复制(第二篇读写分离) mycat 中间件
linux下mysql主从复制(第二篇读写分离) mycat 中间件 接着上篇文档补全,mysql 读写分离,在上篇文章案例下准备好Mycat-server-1.4-release-201510192 ...
- Ubuntu10下MySQL搭建Amoeba_读写分离
一.背景知识 Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与Client.DB Server(s)之间.对客户端透明.具有负载均衡.高可用性.sql过滤.读写分离.可路由相关 ...
- mysql 数据库集群搭建:(四)pacemaker管理三台maxscale集群,搭建mariadb读写分离中间层集群...
为什么80%的码农都做不了架构师?>>> <mysql 数据库集群搭建:(一)VirtualBox中多台CentOS虚拟机间和windows主机间互通以及访问互联网设置& ...
- 数据库应用——Atlas代理MySQL集群实现读写分离
Atlas代理MySQL集群实现读写分离 一.Atlas简介和架构 1.1 环境准备 1.2 配置时间服务器 二.主服务器配置 2.1 master节点1的配置 2.2 master节点2的配置 2. ...
- mysql主从和mycat读写分离的安装及验证
目录 一.背景介绍 二.安装mysql数据库(主从机器都需要先这样安装) 三.主从机配置 1.主服务器进行如下操作 2.从服务器进行如下操作 四.代理服务器安装和配置mycat读写分离 五.主从复制. ...
- MySQL高可用和读写分离
MySQL 高可用和读写分离 文章目录 MySQL 高可用和读写分离 一.从单机到集群 1.1 单机MySQL数据库到几个问题 1.2 单机MySQL到技术演进 二.MySQL的主从复制 2.1 核心 ...
- MySQL 案例实战--MySQL 基于Mycat实现读写分离
MySQL 基于Mycat实现读写分离 前言 一.什么是读写分离? 二.MySQL 读写分离解决方案 三.MySQL 基于Mycat实现读写分离 四.Mycat-web 管理部署 前言 本环境是基于 ...
- 【纯干货】Amoeba实现MySQL主从同步与读写分离
[纯干货]Amoeba实现MySQL主从同步与读写分离 一.简介 amoeba简介 Amoeba(变形虫)项目,该开源框架于2008年开始发布一款 Amoeba for Mysql软件.这个软件致力于 ...
- 【MySQL】基于Docker的Mysql主从复制搭建
基于Docker的Mysql主从复制搭建 为什么基于Docker搭建? 资源有限 虚拟机搭建对机器配置有要求,并且安装mysql步骤繁琐 一台机器上可以运行多个Docker容器 Docker容器之间相 ...
最新文章
- 白噪音和粉红噪音煲机_白噪音真的有助于睡眠?这款可以自定义的应用给你答案...
- 每天2小时,吃透 985博士总结的这份保姆级OpenCV学习笔记(20G高清/PPT/代码)
- 一段Big5繁体转换简体GB2312的程序
- Excel 2016双击无法打开文件的解决办法
- 你真的理解图像处理算法SIFT吗?
- mysql之批量删除
- 人工智能-baidu-aip语音识别(语音转文字)
- CentOS linux系统将UTC时间修改为CST时间
- java对某个字段排序_Java8对List集合对象某个字段进行排序
- 项目延期的4大原因及解决方案!
- [转]VS2013+简单稀疏光束调整库SSBA配置(64位编译)
- 电脑显示your pc android,新版DeX模式不再强调手机变PC,而是让Android融合PC
- 如何完美清除被磁碟机感染的文件?
- 完美世界控股集团发布全新互联网品牌88,推出首款个人免费商务邮箱
- Apostrophe not preceded by \
- PEST分析顺丰服务需求_顺丰内外部环境分析.doc
- Python机器学习应用之监督学习-上证指数涨跌预测实例
- dba怎么报考_2019年报考DBA需要什么条件,要求是不是很高?
- 斐波拉契数列(简单思路)
- uiautomator2安卓测试框架报No tests found for given includes