How to optimize a MySQL database

One of the most important prerequisites for achieving optimal MySQL database performance is indexing. Indexing is an internal MySQL feature that allows faster gathering of data.

Let's take an example table called "sample" with only two rows - "number" and "employee". If you run a simple query such as:

 

 

MySQL will check all records and will return only the one that has its number value set to 4.

But if you have several thousand entries for example, this will be a slow query. In this case we have a unique field - "number". Therefore, we can create an index for it. Indexing will create an internal register that is saved in by the MySQL service. It can be done with the following query:

 

 

Once this index is set, next time you want to get the information for employee number 4, the service will go directly to it using the index and will return the information much faster.

This is just a very basic example. For bigger databases, the difference in the loading time can be significant. Indexing your database can drastically decrease the loading time of your web applications.

There is another query that you can use to increase the loading speed of your database:

 

 

You can use the following command to optimize/repair a database through SSH:

mysqlcheck -orp -u user_name database_name

where:

-o - stands for optimize
-r - stands for repair
-p - when this option is used with the command you will be prompted to enter the password of the database username user_name
-u - the username assigned to the database; in this case you can use your cPanel username with its corresponding password

Alternatively, you can use the detailed instructions in this article:

How to Optimize a MySQL Database with phpMyAdmin

There are other methods which can be used for MySQL optimization such as using of persistent connections, query caching, etc. However, they may require some fine tuning from the Apache and MySQL configuration files.

After the optimization, the MySQL service will take much less time to search in your database which will result in better performance of your scripts.

cPanel is easy to work with when you have the right host to support you. If you need a reliable partner to help you manage your website with cPanel, check out our cPanel hosting services!

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to export/import a MySQL database via SSH

In this article we will show you how to export and import a MySQL database via SSH. Managing your...

Error about legacy type authentication (old-style) when connecting remotely to MySQL

This particular error can occur in some MySQL clients. The reason for it is that our servers...

How to change the password of a Mysql user in cPanel?

If you have already created a MySQL user through the cPanel -> Mysql Databases tool you may...

How to reset the password for a MySQL database?

You may need to change the password of your database in order to improve the security of your...

I cannot create views in MySQL

Regular MySQL users do not have privileges to create views in MySQL. If you try to execute CREATE...

Powered by WHMCompleteSolution

Copyright © 2013<script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script>, HostLantern. All Rights Reserved.