How to Delete MySQL Database and Tables in WordPress?
WordPress from the outlook may have easy to use interface and look simple. But certain times it is necessary to know what happens in the background to have more precise control on your site. Especially when you are a beginner and do everything on your own, it’s a good idea to spend time in understanding the basics to help run your WordPress site for long term. Deleting database table is one such a necessary activity you may need to carry out to keep up the size of your database and run the queries faster.
What is WordPress Database Table?
WordPress runs with PHP and MySQL. While PHP is used to create functions, queries and output at different levels the actual content is separately stored in a MySQL database tables. For example, all text content of your posts is stored in a database table named “wp_posts”.
When the page on your site is loading, the PHP scripts will fetch the required content from the databases tables and show it in the frontend display. This means you need to keep the database trim in order to load the pages faster.
Why You Need to Delete Database Tables?
Well, the power of WordPress can be realized only with the handful of plugins installed on your site. Here comes the problem – most of the plugins create a database tables to store the content in the backend. These tables WILL NOT be deleted even you deleted the plugins from the dashboard. Most of us have the habit of installing and deleting the plugins later due to various reasons. In all such scenarios the table content will be available on the database occupying space and slowing down your site loading speed. Learn how to completely delete W3TC plugin from your WordPress site.
What Type of Plugins Create Database Tables?
It completely depends on the plugin developer to define how the data is to be stored and handled. As far as we checked most of the plugins in the following categories create database tables to store content. The tables are not deleted even after we deleted the plugin files.
- Related posts
- Social login / follow
- Rating and reviews
- Image crushing
Note on certain scenarios it is necessary to keep the content even the plugin is deleted. Custom post types are typical example where the data is still stored in “wp_posts” table and needs to be retained regardless of the plugin is active or deleted.
Let us take one real-time example. We were using one of the popular WordPress related posts plugin for more than a year without any issue. Later we started using Google matched content recommendation and found no need of the earlier related posts plugin. We deleted the related posts plugin and continue to work with the site for months.
Sometimes later when looked up the database for cleaning up, we still found the table related to the old deleted related posts plugin was hanging on. Being a related posts table it has more than 12k entries that were never being used, on the site.
How to Delete MySQL Database Table in WordPress?
Deleting the database table needs the hosting account access and can’t be done through FTP or admin dashboard. Login to you hosting account and locate “phpMyAdmin” tool which is used to maintain your WordPress database.
Once phpMyAdmin is opened, click on your database to see the list of tables part of it. By look you can easily find out the unnecessary tables related to those plugins you might have installed and deleted once upon a time. Before deleting, the first and important thing is to backup entire database for restoring in case of issue.
Click on the “Export” tab and then the custom option. Select all tables and choose the compression type as zipped or gzipped. Click on the “Go” button at the bottom to download the MySQL database to your local computer.
Deleting Unnecessary Database Tables
Click on the required database and then the table you want to delete. Under “Operations” tab click on the option “Delete the table (DROP)”.
You will see a confirmation prompt for deletion as below and press ok to proceed.
Once confirmed, this will delete the table and all the content. The selected table will disappear from database. You can also go to “Query” tab and simple run the query “DROP TABLE TABLE-NAME” to delete the table. In case of any issues, drop the complete database and go to “Import” tab to upload the backup database and restore it.
Completely Deleting MySQL Database from cPanel
If you are a WordPress user most of the popular hosting companies like Bluehost, SiteGround, HostGator, etc. are using cPanel hosting for managing the account. cPanel has lot of options which is difficult for normal beginner level users to get familiar in shorter time frame. One such function is to delete the MySQL database from your WordPress installation.
Why You Need to Delete a Database?
When you manage self-hosted WordPress sites you may need to play around with databases for multiple reasons. Below are some of the scenarios you may need to delete the database:
- When you install WordPress with one-click applications there is also an option to create an automatic database for your WordPress installation. If you have created database during this step but actually you have the backup database for importing then you may need to delete it.
- Cleanup the content of a testing or demo site you have created.
- You are migrating to new host and wanted to delete all the existing content on the old host.
- You wrongly copied the database and wanted to get rid of the duplicate database.
Managing MySQL Database
Your cPanel hosting account offers phpMyAdmin to manage databases. Here you can edit the content of the database tables and delete the table part of any database on your hosting account.
But this tool does not offer an option to delete the complete database.
Deleting MySQL Database
Login to your cPanel account and navigate to the section related to databases. You will see the “MySQL Databases” icon as shown in the below picture (example from Bluehost).
Click on the “MySQL Databases” will take you to the screen where you can view all databases and user details available on your hosting account. Under “Current Databases” section find the one you want to delete.
Click on the “Delete” button and confirm the database deletion.
You will see the successful confirmation message like below.
That’s it!!! You have deleted the database occupying storage space on your server. Now go to phpMyAdmin and you will not find the database anymore.
- Once you have deleted the database check whether you need to delete the database user also.
- If you only want to delete a table from the database, you can do it from phpMyAdmin tool as explained above.
- There are no possibilities of deleting multiple databases or database users from cPanel. You need to delete one by one and confirm the deletion of databases and the users separately.