Home Database Mysql Tutorial MySQL与PostgreSQL:该选择哪个开源数据库?哪一个更好?_MySQL

MySQL与PostgreSQL:该选择哪个开源数据库?哪一个更好?_MySQL

Jun 01, 2016 pm 01:26 PM
database software engineer project

bitsCN.com

Naresh Kumar是一位软件工程师与热情的博主,对编程与新事物充满了激情和兴趣。近日,Naresh撰写了一篇博文,对开源世界最常见的两种数据库MySQL与PostgreSQL的特点进行了详尽的分析和比对。

如果打算为项目选择一款免费、开源的数据库,那么你可能会在MySQL与PostgreSQL之间犹豫不定。MySQL与PostgreSQL都是免费、开源、强大、且功能丰富的数据库。你主要的问题可能是:哪一个才是最好的开源数据库,MySQL还是PostgreSQL呢?该选择哪一个开源数据库呢?

在选择数据库时,你所做的是个长期的决策,因为后面如果再改变决定将是非常困难且代价高昂的。你希望一开始就选择正确。两个流行的开源数据库MySQL与PostgreSQL常常成为最后要选择的产品。对这两个开源数据库的高层次概览将会有助于你选择最适合自己需要的。

MySQL

MySQL相对来说比较年轻,首度出现在1994年。它声称自己是最流行的开源数据库。MySQL就是LAMP(用于Web开发的软件包,包括Linux、Apache及Perl/PHP/Python)中的M。构建在LAMP栈之上的大多数应用都会使用MySQL,包括那些知名的应用,如WordPress、Drupal、Zend及phpBB等。

一开始,MySQL的设计目标是成为一个快速的Web服务器后端,使用快速的索引序列访问方法(ISAM),不支持ACID。经过早期快速的发展之后,MySQL开始支持更多的存储引擎,并通过InnoDB引擎实现了ACID。MySQL还支持其他存储引擎,提供了临时表的功能(使用MEMORY存储引擎),通过MyISAM引擎实现了高速读的数据库,此外还有其他的核心存储引擎与第三方引擎。

MySQL的文档非常丰富,有很多质量不错的免费参考手册、图书与在线文档,还有来自于Oracle和第三方厂商的培训与支持。

MySQL近几年经历了所有权的变更和一些颇具戏剧性的事件。它最初是由MySQL AB开发的,然后在2008年以10亿美金的价格卖给了Sun公司,Sun公司又在2010年被Oracle收购。Oracle支持MySQL的多个版本:Standard、Enterprise、Classic、Cluster、Embedded与Community。其中有一些是免费下载的,另外一些则是收费的。其核心代码基于GPL许可,对于那些不想使用GPL许可的开发者与厂商来说还有商业许可可供使用。

现在,基于最初的MySQL代码还有更多的数据库可供选择,因为几个核心的MySQL开发者已经发布了MySQL分支。最初的MySQL创建者之一Michael "Monty" Widenius貌似后悔将MySQL卖给了Sun公司,于是又开发了他自己的MySQL分支MariaDB,它是免费的,基于GPL许可。知名的MySQL开发者Brian Aker所创建的分支Drizzle对其进行了大量的改写,特别针对多CPU、云、网络应用与高并发进行了优化。

PostgreSQL

PostgreSQL标榜自己是世界上最先进的开源数据库。PostgreSQL的一些粉丝说它能与Oracle相媲美,而且没有那么昂贵的价格和傲慢的客服。它拥有很长的历史,最初是1985年在加利福尼亚大学伯克利分校开发的,作为Ingres数据库的后继。

PostgreSQL是完全由社区驱动的开源项目,由全世界超过1000名贡献者所维护。它提供了单个完整功能的版本,而不像MySQL那样提供了多个不同的社区版、商业版与企业版。PostgreSQL基于自由的BSD/MIT许可,组织可以使用、复制、修改和重新分发代码,只需要提供一个版权声明即可。

可靠性是PostgreSQL的最高优先级。它以坚如磐石的品质和良好的工程化而闻名,支持高事务、任务关键型应用。PostgreSQL的文档非常精良,提供了大量免费的在线手册,还针对旧版本提供了归档的参考手册。PostgreSQL的社区支持是非常棒的,还有来自于独立厂商的商业支持。

数据一致性与完整性也是PostgreSQL的高优先级特性。PostgreSQL是完全支持ACID特性的,它对于数据库访问提供了强大的安全性保证,充分利用了企业安全工具,如Kerberos与OpenSSL等。你可以定义自己的检查,根据自己的业务规则确保数据质量。在众多的管理特性中,point-in-time recovery(PITR)是非常棒的特性,这是个灵活的高可用特性,提供了诸如针对失败恢复创建热备份以及快照与恢复的能力。但这并不是PostgreSQL的全部,项目还提供了几个方法来管理PostgreSQL以实现高可用、负载均衡与复制等,这样你就可以使用适合自己特定需求的功能了。

平台

MySQL与PostgreSQL都出现在一些高流量的Web站点上:

MySQL:Slashdot、Twitter、Facebook与WikipediaPostgreSQL:Yahoo使用了一个修改的PostgreSQL数据库来处理每天数以亿计的事件,还有Reddit和Disqus

MySQL与PostgreSQL都能运行在多个操作系统上,如Linux、Unix、Mac OS X与Windows。他们都是开源、免费的,因此测试他们时的唯一代价就是你的时间与硬件。他们都很灵活且具有可伸缩性,可用在小型系统和大型分布式系统上。MySQL在一个领域上要比PostgreSQL更进一步,那就是它的触角延伸到了嵌入式领域,这是通过libmysqld实现的。PostgreSQL不支持嵌入式应用,依然坚守在传统的客户端/服务器架构上。

MySQL通常被认为是针对网站与应用的快速数据库后端,能够进行快速的读取和大量的查询操作,不过在复杂特性与数据完整性检查方面不太尽如人意。PostgreSQL是针对事务型企业应用的严肃、功能完善的数据库,支持强ACID特性和很多数据完整性检查。他们二者都在某些任务上具有很快的速度,MySQL不同存储引擎的行为有较大差别。MyISAM引擎是最快的,因为它只执行很少的数据完整性检查,适合于后端读操作较多的站点,不过对于包含敏感数据的读/写数据库来说就是个灾难了,因为MyISAM表最终可能会损坏。MySQL提供了修复MySQL表的工具,不过对于敏感数据来说,支持ACID特性的InnoDB则是个更好的选择。

与之相反,PostgreSQL则是个只有单一存储引擎的完全集成的数据库。你可以通过调整postgresql.conf文件的参数来改进性能,也可以调整查询与事务。PostgreSQL文档对于性能调优提供了非常详尽的介绍。

MySQL与PostgreSQL都是高可配置的,并且可以针对不同的任务进行相应的优化。他们都支持通过扩展来添加额外的功能。

一个常见的误解就是MySQL要比PostgreSQL更容易学习。关系数据库系统都是非常复杂的,这两个数据库的学习曲线其实是差不多的。

标准兼容性

PostgreSQL旨在实现SQL兼容性(当前标准是ANSI-SQL:2008)。MySQL则兼容大部分SQL,不过还有自己的扩展,可以支持NoSQL特性,这在参考手册中都有介绍。每种方式都有优缺点。兼容标准会让数据库管理员、数据库开发者与应用开发者更舒服一些,因为这意味着他们只需学习一套标准、一套特性和命令即可。这会节省时间,提升效率,也不会被锁定在特定的厂商上。

支持使用非标准的自定义功能的人们认为这样可以快速采用新的特性,而不必等待标准进程完成。ANSI/ISO标准在不断演化,因此标准兼容性也是个变化的目标:知名的关系型数据库Microsoft SQL Server、Oracle与IBM DB2也只是部分兼容于标准。

结论

虽然有不同的历史、引擎与工具,不过并没有明确的参考能够表明这两个数据库哪一个能够适用于所有情况。很多组织喜欢使用PostgreSQL,因为它的可靠性好,在保护数据方面很擅长,而且是个社区项目,不会陷入厂商的牢笼之中。MySQL更加灵活,提供了更多选项来针对不同的任务进行裁剪。很多时候,对于一个组织来说,对某个软件使用的熟练程度要比特性上的原因更重要。

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1583
276
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL: A Beginner-Friendly Approach to Data Storage MySQL: A Beginner-Friendly Approach to Data Storage Apr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

See all articles