In this blog on the ‘MongoDB vs MySQL comparison’, I’ll break down database jargon to explain the difference between the newer system and the legacy that is MySQL. While a lot of the terms associated with this topic might be familiar to many web professionals out there, I’m laying it all out to help those who could do without the techspeak. So let’s get started!
MySQL and MongoDB are ‘database management systems’. To really understand the difference, let’s first look at what a database is:
What are databases?
Databases are applications that store collections of data, organised in a certain way. Data can include information and content ranging from lists of products to images, videos, personal information and more.
What can databases do?
For several reasons including security and speed, storing data in a file system on a separate computer is not a sensible route to meet the requirements of websites today.
Databases help you easily and efficiently create, access, search for and replicate the data of your website. The software that helps manage that database is called a ‘Database Management System’ or DBMS.
DBMS – MongoDB vs MySQL :
There are various Database Management Systems and each organizes data in a certain way. We call these ‘database models’. Some examples of database models include the ‘relational model’ and a newer model known as the ‘non-relational model’. MySQL uses the former model and MongoDB the latter.
Data in a relational database is sorted into tables and relations or links are made between data in different columns, rows and other tables. A table in a database would look similar to an excel spreadsheet with columns, rows and an index. Relational databases receive commands/requests or ‘queries’ in SQL or a structured query language that will combine data from different tables to fulfil your ‘query’.
SQL is the language used for creating, inserting, storing, updating, deleting, retrieving and manipulating data in databases.
MySQL is the most popular database management system in the world. Used largely for web-based applications and popular for its ease-of-use and tested performance over the years.
Why do most web developers prefer to work with MySQL?
- It’s open-source: Only enterprises need to purchase a license
- It has wide usage: Usually comes integrated with most web hosting accounts like your Linux Shared Hosting package and can be widely used on most platforms such as Linux, Windows, Ubuntu, Mac OS X, etc
- It’s easy to use
- It’s reliable: as been a tried and tested over the years
- It works well with PHP and can also be used with other programming languages such as JAVA, PERL, C, C++ and more
- Works well for small and large applications
What are the downsides to relational databases and MySQL?
- Scalability: Adding more data to a certain record could involve expanding to several tables, columns and rows
- Speed: Dispersing data due to the very structure of it does sometimes take a while
- It’s difficult for the managers of the database to insert new data because of this complexity
- You need to write the schema to define the table first before using it
As you can see, the most popular DBMS are ‘relational’, with usage of the top 3 dipping in the last few months. The only non-relational database to break into this trend is a database known as ‘MongoDB’ and as you can see, its numbers are growing.
MongoDB is an open-source database system that uses the ‘document model’. Unlike MySQL (introduced in 1995), MongoDB is a newer database management system (released in 2009) and is making a strong impact on the modern web world. The company reported strong growth numbers for the first quarter of 2018 and its database model is disrupting the industry. Microsoft recently introduced an API that will enable the use of MongoDB on its Azure Cosmos DB that it launched in 2017 and Google announced further use of MongoDB on Google Cloud.
Non-relational databases/NoSQL and MongoDB:
Non-relational databases organize data very differently. While there are 4 types of non-relational databases, I will only focus on one today i.e the ‘document-based model’ which is what MongoDB uses. This database organizes data into documents- more specifically, JSON documents. JSON is a format for easy data exchanges between humans and machines. JSON documents provide a more flexible data structure than the traditional SQL-structured databases as new fields can be added at any time and also have any type of data value. This is a huge help for companies who have to deal with large volumes of data. Many today consider RDMS to be unable to meet the expectations from today’s data-intensive applications. Unlike MySQL, databases that are non-relational can store unstructured data such as user logs, sessions, images, videos, chats and also data from IoT devices.
What makes MongoDB so attractive?MongoDB can support the following:
- Flexibility- Firstly, the document structure is more in line with how developers code in their respective programming languages which is clear and structured in key-value pairs. This makes it easier to add and edit data/documents at any time. In a relational database, this would involve the database having to be restructured
- Faster turnaround time-because related data which would be stored across several tables in a MySQL database are stored in the same document in a MongoDB
- No strict schemas followed-you are allowed to create a document first before defining the structure of the document, making it very helpful for businesses who in a start-up phase who are unsure of what their database structure should look like
- Like we mentioned, MongoDB’s features make it better suited to those who handle huge volumes of data
What are the downsides to MongoDB?
- Since this is a newer database, unless you train yourself, the number of experts in MongoDB are fewer than the ones in MySQL
- MongoDB is known to eat up a lot of server memory
Are MySQL and MongoDB similar in any way?
- Both use indices- if an index is missing, the entire database must be scanned to find a match to the query
- License-both are Open-source
- Security risks-honestly, the verdict still out on this one. Take adequate security safeguards when using both systems
MongoDB vs MySQL comparison – summary
|Released||1995- currently in its 8th version in 2018||2009|
|Speed||Slower than MongoDB||Faster than MySQL. Its structure speeds up the development process|
|Flexibility||Not so much- need to define your DB schema first before using it||Considerable flexibility compared to MySQL- defining a schema not required|
|Scalability||Harder to scale, but possible. MySQL databases are vertically scalable- you can add more resources to a single server||More scalable than MySQL. MongoDB is horizontally scalable, you can add more servers to expand your database|
|DB Administrator required||Yes||No – can be used by both developers and administrators|
|Ideal for|| Accounting firms and banks – and other companies that |
require structured data with clear schema. Ideal for
businesses with more or less fixed requirements. Twitter is one large company
that defies this and is one of the largest users of MySQL
| Ideal for business with real-time data, IoT, content management, mobile apps, social networks, |
big-data/web analytics oriented systems and those that do not require structured
data with clear schema or their schema continues to change. Ideal for businesses where requirements are more fluid.
It’s clear from this MongoDB vs MySQL comparison that both systems have their pros and cons. MongoDB wins for speed and scalability while the badge for security (in comparison at least) can be awarded to MySQL. Several articles tout the newness of MongoDB and refer to MySQL as an old-fashioned, outdated system. This could not be further from the truth. Non-relational databases are just an alternative technology.