Mysql支持几种不同形式的复制如:单双向、链式级联、异步复制。在复制过程中,一个服务器充当主服务器(master)而一个或多个其他
一、MySQL主从复制原理
什么是mysql主从复制介绍
Mysql支持几种不同形式的复制如:单双向、链式级联、异步复制。在复制过程中,一个服务器充当主服务器(master)而一个或多个其他的服务器充当从服务器(slave)如果设置了链式级联复制,那么从slave服务器除了当从服务器,还会作为其他服务器的主服务器。
当配好主从复制后,数据库的内容更新应该都在master服务器上,避免用户对主服务器上数据库内容的更新与对从服务器上数据库内容的更新发生了冲突。生产环境中一般会忽略授权表的同步,对在从服务器上的用户仅授权select读权限。或在my.cnf配置文件中加read-only参数,来确保从数据库只读,当然二者同时操作效果更佳。
一般生产环境中会有一个M-->S 或者是一个M-->多个S。在同步的时候还可以双向同步MM.而级联就是A-->B-->C-->D.在从库的my.cnf配置文件中加read-only参数来确保从库只读。常规情况是不允许的,当然如果能够保证不对同一个表写数据可以了。或者我们在从库上只对用户授权select权限。
mysql主从结构的作用:
1)主从服务器架构的设置,可以大大加强数据架构的健壮性,当主服务器出现问题时,我们可以切换到从服务器继续提供服务。
这类似我们说的NFS存储数据通过inotify+rsync实时同步到备份的nfs上的过程。只不是这里是同步mysql数据库的内容而已,用的是mysql自带的工具。
2)主从服务器价格可实现对用户的请求实现读写分离,即通过在从服务器上处理用户select查询请求,降低用户查询响应时间。及读写给主服务器带来的压力。对于更新的数据(update,insert,delete)仍然交给主服务器处理,确保主服务器和从服务器保持实时同步。
如果网站是以非更新为主的业务,如blog,www首先展示等业务,读请求比较多,这时从服务器的负载均衡策略就很有效了,这就是读写分离数据库结构。
3)可以把几个不同的从服务器,根据公司的业务进行拆分,比如有为外部用户提供查询服务的从服务器,有用来备份的从服务器,还有提供公司内部后台、脚本、日志分析及开发人员服务的从服务器。这样拆分除了减轻主服务器的压力外。使得对外用户浏览,对内处理公司内部用户业务,及DBA备份业务互不影响。具体可以看下面的简单架构来说明:
我们现在是一主5从,只要我们向这1主写数据,那么5从就都会同时更新。提示:其中s1 2 3 可以通过lvs做成负载均衡的模式。这样第4台从库给我们的后台,内部访问。
后台的数据库独立出来,安装在备份数据库上,这样我们测试使用的数据就不会影响到线上的环境,也能够保证真实情况。而我们的备份数据库,,要开启binlog功能,做数据库的增量备份功能。
-------小结----------------------------------------------------------------
数据库主从同步跟sersync实时同步是一样的道理。只是我们的sersync是同步文件,而我们这次是同步数据库数据而已。MySQL同步是利用自带的工具来进行同步。主从架构我们可以在从库上执行select查询请求,降低用户查询响应时间及读写给服务器带来的压力。在数据库里面,还有这样的问题:当数据库在更新的时候是没办法做其他操作的如查询。对于更新数据一般都是通过update inserter delete。
如果网站是以非更新的业务为主(浏览为主),读请求比较多,那么这时候从服务器的负载均衡策略就很有效了。这就是传说中的读写分离结构。从库的作用还有很多不同的用途。有为外部用户提供查询服务的从服务器,有用来备份的从服务器,还有提供公司内部后台,脚本,日志分析及开发服务的从服务器。这样拆分能够减轻主服务器的压力。
-------小结----------------------------------------------------------------
相关阅读:
RHEL 6.4(i386)安装MySQL 5.6的方法
Linux网站架构系列之Apache----部署篇
MySQL完整安装和主从双机配置
RHEL6平台rpm方式安装MySQL数据库
RedHat 6.3安装MySQL-server-5.6.13-1.el6.x86_64.rpm
Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
