Start a conversation

How to optimize a MySQL database

Usually, for a website having a large volume of data, optimizing the MySQL database becomes crucial for enhancing the performance to indexing. Indexing helps in a better collation of data and is an internal feature that comes with MySQL.

Consider a table “abc” that has a set of rows may be 2 wherein one row would have a set of numbers and the second having the relevant name/details of the individual. What most webmasters would do is, run a basic query stated below :

SELECT * FROM sample WHERE number = 5;

In this case, what MySQL does is, it runs through all the information that is there in the database and give a result which has a value set of 5. But, this query would probably prove ineffective if you have a large data ie. there are say a trillion entries in the table. This query would take a lot of time for generating an expected result.

But, since you have a distinct “number” field, an index can be created. By creating an Index, you would be basically creating an internal register which gets saved in by the MySQL itself. The below query can be used for creating an Index :

ALTER TABLE sample ADD INDEX (number);

Upon creation and setting of the Index, later whenever you wish to fetch some information pertaining to the individual who has been assigned the number 5, the service would straight-way go to it by using the index, hence generate a result at a much faster pace than the earlier query.

Assuming that you have even larger database, then its loading time would make a significant difference in the process of Indexation which can take longer time hence result in a degraded performance of your web applications due to slower load time.

Here, in such a case it becomes necessary for you to optimize your MySQL Database by using the below query which would enhance the speed and decrease the loading time of your database:

OPTIMIZE TABLE sample;

Upon optimization, your MySQL service would take lesser time for searching through your database and offer results in a drastically reduced time, hence avoiding any unwanted load on your database, which would ultimately result in a better overall performance of your web applications.

Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Benajir Kamal

  2. Posted

Comments