MySQL VS MongoDB




MySQL VS MongoDB
MySQL is a relational database management system whereas MongoDB is NoSQL database where NoSQL stands for Not Only SQL. MySQL and MongoDB both are open source product distributed under the GNU GPL and also available as commercial version. MySQL (Relational database) is excellent for representing and working with sets of data but is not good at scaling, here emerges MongoDB (NoSQL) databases since they have this unique characteristic to scale across servers.



MySQL
MySQL was created by a Swedish company MySQL AB, founded by David Axmark, Allan Larsson and Michael widenius around 1995.
MySQL is a very popular database and it is world’s second most widely used RDBMS. MySQL database is popularly used for web applications and it is also one of the major component of widely use LAMP stack (Linux, Apache, MySQl, Perl/PHP/Python).
MySQL Databases store data in the form of tables, the tables are further divided into rows and columns where each column contains same kind of data and the rows contain group of related data. SQL (structured query language) is one of the common standardized language used to access MySQL database.

ADVANTAGES

Some of the advantages of MySQL Databases are:
Fast: Even though MySQL provides fewer advantages as compared to other databases but it still have all the features required by database developers.
Easy to use: With simple SQL statements one can interact with MySQL, so basic knowledge of SQL is required for MySQL.
Secure: MySQL is very secure because it has a strong data security layer that protects the data, the passwords are encrypted to protect the data from intruders.
Inexpensive: MySQL is available free from MySQL website.
Scalable: MySQL can handle data up to 50 million rows or more. Default file size limit is 4GB however it can be increased up to 8TB of data (theoretically).

DISADVANTAGES

MySQL database is limited in areas like data warehousing, fault tolerance and performance diagnostics and it isn’t fully SQL compliant.
MySQL performs better on low writes/read ratio as compared to high read/writes ratio.
MySQL have table and Database structure because of this it do not scale well horizontally by adding more sever to divide the load.




MongoDB

MongoDB is a document-oriented, NoSQL database. The data models are persistence strategies built for high read and write throughput. MongoDB have the ability to scale easily with automatic failover.
MongoDB is an attractive database because of its document based data model, with this the complications of table joins provided by the relational database could be avoided. MongoDB is a very powerful, flexible and scalable general – purpose database. Some of its major features are ability to scale out with range queries, sorting aggregation and geospatial indexes.

ADVANTAGES 

Some advantages of MongoDB are:
Easy to use: MongoDB is a document-oriented database with this, the scaling out became much easier and it also made it possible to represent the complex hierarchical relationship with single record. MongoDB have no Pre-defined schema.
Scaling: The size of the data of applications are growing at fast pace due to which even small scale application need to store more data because of this growing data the scaling of data becomes an crucial decision for the developers. Database can be scaled in two ways scaling up (bigger machine to store data) or scaling out (partitioning data across machines). Scaling up is often very expensive and a physical limit is reached eventually.MongoDB is designed to scale out. Its document oriented data model makes scaling out process easier since the data can be split easily across multiple servers.



Unique features: MongoDB provide some unique features:
Indexing: MongoDB supports secondary indexes allowing the process of querying even faster.
Aggregation: MongoDB support complex aggregation from sample pieces with this the database can easily optimize it.
Special Collection types: MongoDB supports time-to-live collection and fixed size collections.
File Storage: MongoDB supports an Easy-to-use protocol through which it can store large amount of data.

DISADVANTAGES
MongoDB have high chances of losing data (when replication of data is not done) and sometimes it is hard to retrieve data.
No joins, therefore when a functionality like this is required multiple queries are done.
Memory usage, MongoDB use more memory due to the duplicity of data since there is no possibility of joins.
 

Comparison of MySQL and MongoDB

Terminology
The various SQL terminologies and the corresponding MongoDB terminology are presented in the following table:                                                                                                  
MySQL Terms
MongoDB Terms
Database
Database
Table
Collection
Rows
Document
Columns
Fields
Index
Index
Table joins
Embedded documents and linking


Data Layout for Collections in MongoDB
MongoDB is a schema less Database. The collection of a mongoDB looks like this.
>db.createCollection(“himy”)
// this command creates a new collection
>db.himy.insert({“name” : “pooja” , “lastname” : “Kapoor”})
>db.himy.insert({“name” : “pooja” , “lastname” : “Kapoor”})
// through this command documents are inserted in the collection
>db.himy.find().pretty()
//this query display all the document of the collection


Here we can see that the same collection can hold documents of different data types with different number of fields because of this feature MongoDB is called a schema less database.

Data Layout for tables in MySQL
MySQL is database have schema. The table in MySQL looks like this.
Create table himmyy( I int, name varchar(10));
//new table is created with two columns I and name.
Insert into himmyy value (1 , ‘pooja’);
//two values are inserted.
Select * from himmyy;
// this query selects all the records of the table.

In Mysql the data type are specified when the table is created so the value entered should match the predefined data type otherwise the table will not accept the value.


Conclusion

MySQL and MongoDB are two completely different databases. MySQL is a RDBMS and the data is stored in the form of rows and columns, it is best suited for structured data. Whereas MongoDB is a document oriented database and it is best for unstructured data. Therefore it completely depends on the need of the application. 
Previous
Next Post »

Popular Posts