How to optimize website database
- Category : MySQL Question
- Posted on : Mar 18, 2021
- Views : 915
- 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:
CMS | Path to the configuration file | Line |
---|---|---|
WordPress | installation root folder, wp-config.php | define('DB_NAME', 'cpuser_database'); |
Joomla | installation root folder, configuration.php | public $db = 'cpuser_database'; |
PrestaShop | installation root folder >>/config/settings.inc.php | define('_DB_NAME_', cpuser_database'); |
OpenCart | installation root folder, config.php | define('DB_DATABASE', 'cpuser_database'); |
Drupal | installation root folder >>/sites/default/settings.php | 'database' => 'cpuser_database', |
Moodle | installation root folder,config.php | $CFG->dbname,= 'cpuser_database'; |
Magento | installation root folder >>/app/etc/local.xml | <[! CDATA [cpuser_database] ]> |
phpBB | installation 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
Categories
- cPanel Question 47
- cPanel Software Management 29
- cPanel Tutorials 13
- Development 29
- Domain 13
- General 19
- Linux Helpline (Easy Guide) 156
- Marketing 47
- MySQL Question 13
- News 2
- PHP Configuration 14
- SEO 4
- SEO 42
- Server Administration 84
- SSL Installation 54
- Tips and Tricks 24
- VPS 3
- Web Hosting 44
- Website Security 22
- WHM questions 13
- WordPress 148
Subscribe Now
10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!Archive Calendar
Sat | Sun | Mon | Tue | Wed | Thu | Fri |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Recent Articles
-
Posted on : Sep 17
-
Posted on : Sep 10
-
Posted on : Aug 04
-
Posted on : Apr 01
Tags
- ts
- myisam
- vpn
- sql
- process
- kill
- tweak
- server load
- attack
- ddos mitigation
- Knowledge
- layer 7
- ddos
- webmail
- DMARC
- Development
- nginx
- seo vpn
- Hosting Security
- wireguard
- innodb
- exim
- smtp relay
- smtp
- VPS Hosting
- cpulimit
- Plesk
- Comparison
- cpu
- encryption
- WHM
- xampp
- sysstat
- optimize
- cheap vpn
- php-fpm
- mariadb
- apache
- Small Business
- Error
- Networking
- VPS
- SSD Hosting
- Link Building
- centos
- DNS
- optimization
- ubuntu