DEV Community

loading...

MySQL vs. MongoDB

gyi2521 profile image gyi2521 ・2 min read

Recently, I learned about MySQL from my Coding Boot Camp class in addition to MongoDB which has been the main database we used in the class. I wanted to share what I have learned so far about these two databases.

The main difference is that MySQL uses structured query language (SQL) while MongoDB uses NoSQL. What is the difference between SQL and NoSQL? In one of the blogs I read, it used an analogy as living in a town where everyone speaks the same language vs. a town where people speak different languages.

SQL databases use structured query language (SQL) for defining and manipulating data. This is extremely powerful, but it can be restrictive. SQL requires that you use predefined schema to determine the structure of your data before you work with it. In addition, all your data must follow the same structure.

A NoSQL database, on the other hand, has dynamic schema for unstructured data, and data is stored in many ways: it can be column-oriented, document-oriented, graph-based or organized as a Key Value store.

MySQL is an extremely established database, meaning that there’s a huge community, extensive testing and quite a bit of stability. It is open source and free. It is available for all major platforms, including Linux, Windows, Mac, BSD and Solaris.

MongoDB, on the other hand, is a non-relational database that stores data as ‘documents’ in a binary representation called BSON (Binary JSON). It gives you flexibility to change your data schema without modifying any of your existing data. MongoDB is horizontally scalable, which helps reduce the workload and scale your business with ease. It is flexible, so you can add new columns or fields on MongoDB without affecting existing rows or application performance.

I will wrap up with some query examples below.

Select/Get statement:

MySQL: SELECT * FROM inventory
MongoDB: db.inventory.find({})

Insert/Post statement:

MySQL : INSERT INTO inventory (item_id, type) VALUES ('ab123', ‘electronics’)
MongoDB: db.inventory.create({item_id: ‘ab123’, type: ‘electronics’})

Thanks for reading!

Discussion (1)

pic
Editor guide
Collapse
vjnvisakh profile image
Visakh Vijayan

I didn't know the BSON part. Good read.