bitsCN.com
之前研究数据库的高可用性,需要用到数据库的同步和备份,下面是我对MySQL的HA的一些研究。
根据《MySQL 5.0 Reference Manual》中提供的HA方案,主要由以下几种:
Requirements
MySQL Replication
MySQL Replication + Heartbeat
MySQL Heartbeat + DRBD
MySQL Cluster
MySQL + memcached
Availability
Automated IP failover
No
Yes
Yes
No
No
Automated database failover
No
No
Yes
Yes
No
Typical failover time
User/script-dependent
Varies
App dependent
Automatic resynchronization of data
No
No
Yes
Yes
No
Geographic redundancy support
Yes
Yes
Yes, when combined with MySQL Replication
Yes, when combined with MySQL Replication
No
Scalability
Built-in load balancing
No
No
No
Yes
Yes
Supports Read-intensive applications
Yes
Yes
Yes, when combined with MySQL Replication
Yes
Yes
Supports Write-intensive applications
No
No
Yes
Yes
No
Maximum number of nodes per group
One master, multiple slaves
One master, multiple slaves
One active (primary), one passive (secondary) node
255
Unlimited
Maximum number of slaves
Unlimited (reads only)
Unlimited (reads only)
One (failover only)
Unlimited (reads only)
Unlimited
对于方案的研究如下,文字性的比较多。
一、 MySQL Replication
对于单一的MySQL同步功能,因无法实现IP地址的自动切换,而该表中所列的功能是MySQL Replication的单向同步工作方式,需要改进为双向同步,就可以实现数据的双向同步、重同步、数据库切换的功能。
二、 MySQL Replication+Heartbeat
对于第二种方案,引入了heartbeat,所以可以实现IP地址切换,heartbeat只针对主机和网络故障的切换,无法监控数据库故障,所以需要额外的工具和配置,而且MySQL Replication的工作机制为异步通讯方式,对同步的数据的一致性可能产生影响。
三、 MySQL+Heartbeat+DRBD
对于第三种采用了DRBD,DRBD是Distributed Replicated Block Device,是基于内核开发的一个虚拟块设备的工具,该软件可以在一个实际块设备或分区上虚拟一个块设备,并挂载到系统之上,两台主机通过配置,来同步块设备上的数据,能够实现双向实时同步的功能,但同时只能有一台主机处于活动状态,从服务器上的虚拟块设备无法挂载,从而不能启动从服务器的MySQL服务,在切换时需要从服务器控制启动顺序,按顺序切换DRBD,挂载虚拟块设备,启动MySQL,调试中该时延较长。而且DRBD基于内核,在应用调试中,多次导致服务器内核出问题而导致主机死机,所以对于服务器的高稳定需求不满足。
四、 MySQL Cluster
集群方式一般应用在负载均衡,采用单向同步的方式,对数据的修改只在一台数据库服务器上进行,对于查询则交给其他的数据库服务器,同时无法完成IP地址的自动切换,所以没有调试
五、 MySQL+memcached
这种方案采用共享内存的方式,使多个MySQL共享同一内存缓冲区,故不适用备份的目的。
六、 其他方案
1. MySQL Proxy:
对于IP地址切换的功能,也可以采用MySQL Proxy来实现,其工作原理是在MySQL Server和Client之间添加一个代理设备,通过lua脚本来处理数据请求,可以根据业务需求用lua脚本实现不同的功能,但这种方式将多添加一台MySQL Proxy服务器,所以不考虑。
2. MyBalance和MyReplication
对于同步功能,除了MySQL本身的同步和DRBD外,还有MyBalance和MyReplication两个工具可以实现,但这两个工具只能进行单向同步,不适合双向备份的目的,所以无法满足需求。
本文出自“技术成就梦想”
bitsCN.com
InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools