WordPress database is used to collect anything important of your website, including plugins, themes and posts, which is just like a core of a WP site. Once completing WordPress installation, the database is created automatically and that includes a list of tables with the default prefix “wp_”. Most users leave it to the default and never change it. As a matter of fact, you need to change WordPress database table prefix.
Hackers can guess and target the database tables with default prefix without paying too much effort. They stand a good chance to attack those databases. To avoid such embarrassing situation, you should change WordPress database table prefix thereby improving website security. Two methods are introduced in the following guide, one is using phpMyAdmin and another is using WordPress plugin.
Make Some Preparations
Backup your database before continuing with the following step-by-step guide. The command method is to backup database in cPanel. Also, you can achieve the same purpose by using a WordPress backup plugin. BackWPup and WP-DB-Backup are recommended here. One is used to backup the whole website and another is used to backup database tables only. Select the more suitable one as needed.
Having completed database backup, it’s time to change database table prefix in WordPress. Start with the first method that helps you make a hit by using phpMyAdmin.
Method 1: Change Database Table Prefix using phpMyAdmin
Step 1: Modify wp-config.php File
Consume that you are using a cPanel hosting solution that is featuring phpMyAdmin. We would like to finish all steps via cPanel. First of all, go to cPanel > File Manger and target your WordPress root directory. Open wp-config.php file and search for the following lines.
The wp_ included in $table_prefix = ‘wp_’; should be the default WordPress database table prefix. Replace it to any other prefix as needed. Note that, the prefix can be comprised by letters, underscores and numbers. We set our database table prefix as the following example.
$table_prefix = 'wp_45678';
Step 2: Change the Prefix of All WordPress Database Tables
We would like to finish this step by using phpMyAdmin that is a great method for MySQL database management. Log into cPanel and go to Databases > phpMyAdmin. Browse the left column and select your website database. By default, 11 tables are shown under the Structure tab, which should be like the following example.
And now, you should replace all default database table prefixes. It seems a troublesome business for you to change the table prefix one by one. Fortunately, the SQL query can help you save a lot of trouble. Turn to the SQL tab and this is where to run SQL query/queries on server.
Use the following lines to replace “wp_” table prefix to the one that you have set in wp-config.php file just now. In this guide, we have customized our database prefix as wp_45678. The SQL queries should be shown as below.
RENAME table `wp_commentmeta` TO `wp_45678_commentmeta`; RENAME table `wp_comments` TO `wp_45678_comments`; RENAME table `wp_links` TO `wp_45678_links`; RENAME table `wp_options` TO `wp_45678_options`; RENAME table `wp_postmeta` TO `wp_45678_postmeta`; RENAME table `wp_posts` TO `wp_45678_posts`; RENAME table `wp_terms` TO `wp_45678_terms`; RENAME table `wp_term_relationships` TO `wp_45678_term_relationships`; RENAME table `wp_term_taxonomy` TO `wp_45678_term_taxonomy`; RENAME table `wp_usermeta` TO `wp_45678_usermeta`; RENAME table `wp_users` TO `wp_45678_users`;
By the way, we suggest you to edit the following lines via an editor, like Notepad++. And then, copy and paste them to the SQL tab. Click “Go” button to run those SQL queries.
Having the default database table prefix changed, you should check if everything goes well via Structure tab.
Step 3: Check If There Everything Goes Well on Your Site
Check if all web pages are accessible from website frontend. And then, test everything included in the WP admin. If there is nothing wrong with your site, backup the database again by using the method we’ve mentioned in the “Make Some Preparations” section.
Method 2: Change Database Table Prefix using WordPress Plugin
The method 2 is introduced to users who prefer to solve problems with WordPres plugin. WordPress developers have launched various plugins for changing default database table prefix. The selected plugin is Change DB Prefix. This plugin enables an easy manner for you to replace the default database table prefix with another one.
Log into your website backend and search for Change DB Prefix via Menu > Plugins > Add New. Install and activate this plugin. And then, a new option “Change DB Prefix” is shown under Menu > Settings.
Go to Menu > Settings > Change DB Prefix and here comes an intuitive setting page for changing database table prefix. First of all, you need to ensure the wp-config.php file is writable and get the right to change your database. And then, get started to execute this plugin.
Here come two fields available for the customization of database table prefix. One is “Existing Prefix” and another is “New Prefix”. Enter the default prefix wp_ in the first field and then type a new prefix in the second field. Click “Save Changes” button to confirm all settings. This plugin allows users to change existing database table prefix in anytime if needed.