HostSEO Blog

Stories and News from IT Industry, Reviews & Tips | Technology Blog


How to optimize website database

  • Category : MySQL Question
  • Posted on : Mar 18, 2021
  • Views : 970
  • By : HostSEO

Database can store a tremendous amount of information â$“ all the posts, pages, comments, menus and any form of text data. The more developed site you have, the larger its database is. Along with it, the database may become 'cluttered' with the unnecessary items, like spam comments, drafts, closed or temporary files, etc.

Of course, it can result in your website poor speed performance, and even resource overusage of your cPanel account â$“ a number of MySQL requests to a 'heavy' database may stuck in a queue hitting Entry Processes and CPU limits. Thus, a proper optimization is required to involve the efficiency with which data is retrieved from the database.

This guide will show you several ways to achieve this goal.

1. To begin with you need to locate the database assigned to your website. If you do not know its name, feel free to check it your website's configuration file:

CMSPath to the configuration fileLine
WordPressinstallation root folder, wp-config.phpdefine('DB_NAME', 'cpuser_database');
Joomlainstallation root folder, configuration.phppublic $db = 'cpuser_database';
PrestaShopinstallation root folder >>/config/settings.inc.phpdefine('_DB_NAME_', cpuser_database');
OpenCartinstallation root folder, config.phpdefine('DB_DATABASE', 'cpuser_database');
Drupalinstallation root folder >>/sites/default/settings.php'database' => 'cpuser_database',
Moodleinstallation root folder,config.php$CFG->dbname,= 'cpuser_database';
Magentoinstallation root folder >>/app/etc/local.xml<[! CDATA [cpuser_database] ]>
phpBBinstallation root folder, config.php$dbname = 'cpuser_database';



2. In our case we have a WordPress-based website, our database name is nctests_wp255:



3. Before making any changes, we strongly advise that you download the backup of your database. To do so, move to Files section > Backup menu:



4. Click on the database in question in Download a MySQL Database Backup menu to start the download:



5. Now you can proceed with the optimization itself. Navigate to Databases section> phpMyAdmin menu:



6. Click on the database in the left menu to expand the list of the tables:



7. Checkmark the needed table and select Optimize table from the drop-down menu as shown below:



8. In the same way you can optimize several tables at once, or all of them using Check All option:



9. As a result, you will get the following output:



10. Another way to get your database optimized is to remove the unnecessary data. It can be done via SQL command line with the following query:

DELETE FROM $table where ;

where $table defines the name of the table that should be adjusted and defines the changes that should be performed:



11. Let's take a closer look at this option and consider the way it works.

Suppose, that you need to remove all the posts that contain some key word, the following command should be used:

DELETE FROM 'table'
WHERE 'column' like '%keyword%
'

NOTE: you need to replace table and column with the actual values of your database.

To do so, move to the table that contains posts of you website and find the corresponding column. In our case it is wp9x_posts and posts_title column:



Below you can see the final variant of our command:

DELETE FROM 'wp9x_posts'
WHERE 'post_title' like '%test%'




Once you hit Go, all the posts that have 'test' word in their title will be removed.

The output will look like:



12. If you wish to remove the posts for the specified period, feel free to use this one:

DELETE FROM 'table'
WHERE 'column' between 'datefrom' and 'dateto'


Again, table and column should be replaced with the actual values as well as datefrom and dateto.

NOTE: you need to specify the precise date and time which can be looked up in the database.



Our final command is:

DELETE FROM 'wp9x_posts'
WHERE 'post_date' between '2015-06-24 19:48:14' and '2016-07-20 23:27:23'


13. Suppose, that you need to remove the comments from a certain user. Here is the command to use:

DELETE FROM 'table'
WHERE 'column' = 'username'


which in our case is:

DELETE FROM 'wp9x_comments'
WHERE 'comment_author' = 'test_user'


or if you need to remove the posts with a certain status:

DELETE FROM 'table'
WHERE 'column' = 'status'


which in our case is:

DELETE FROM 'wp9x_posts'
WHERE 'post_status' = 'closed'


The same mode works for any other tables, columns and databases, you just need to set the corresponding values. You can also refer to MySQL documentation to learn more about possible manipulations and MySQL syntax.


That's it!

              
                      Need any help? Contact our HelpDesk

 

Subscribe Now

10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!

Archive Calendar

SatSunMonTueWedThuFri
 123456
78910111213
14151617181920
21222324252627
28293031 

Born in 2004 ... Trusted By Clients n' Experts

SEO Stars

They never made me feel silly for asking questions. Help me understand how to attract more people and improve my search engine ranking.

Read More

Emily Schneller Manager at Sabre Inc
SEO Stars

Took advantage of Hostseo's superb tech support and I must say, it is a very perfect one. It is very fast, servers reliability is incredible.

Read More

Leena Mäkinen Creative producer
SEO Stars

We're operating a worldwide network of servers with high quality standards requirements, we’ve choose hostseo to be our perfect partner.

Read More

Ziff Davis CEO at Mashable
SEO Stars

It’s very comfortable to know I can rely about all technical issues on Hostseo and mostly that my website and emails are safe and secured here.

Read More

Isaac H. Entrepreneur
SEO Stars

With hostseo as a hosting partner we are more flexible and save money due to the better packages with great pricing, free SEO n' free SSL too!

Read More

Madeline E. Internet Professional