SQL Scripts to Change Default _wp WordPress Database Prefix

Increase Security of WordPress Database

Where is all information and content about your WordPress site is stored? It is the WordPress database. Hence, the database is the first place where hackers will try their luck and attack. Spammers and hackers will try to run automated codes for SQL injections. If you do not change the default database prefix while installing the WordPress, you are more vulnerable to an attack. Hackers will first try and attack default _wp prefix.

In this blog post, I am sharing with you the SQL scripts which will help you in changing the default _wp database prefix properly within minutes.

Preparation

I suggest that you take a back up of your existing database.

Change Database Table Prefix

You will have to rename the database tables and to do this all you need is access to PhpMyAdmin.

PHP My Admin

PHP My Admin

Let us assume that for security reasons you want to change WordPress database prefix from ‘_wp’ to ‘_wp_zjdu_’. I am sharing with you a list of SQL scripts that if executed will change the default _wp database prefix to _wp_zjdu_ by renaming tables.

  1. Log into phpMyAdmin
  2. Choose correct database
  3. Click on SQL tab on the top
  4. Copy & paste below SQL queries, click on Go
Database Structure

Database Structure

SQL Scripts:

Copy and execute below scripts all at once, this will change default prefix _wp to _wp_zjdu_ by renaming tables.

RENAME table `wp_commentmeta` TO `wp_zjdu_commentmeta`;
RENAME table `wp_comments` TO `wp_zjdu_comments`;
RENAME table `wp_links` TO `wp_zjdu_links`;
RENAME table `wp_options` TO `wp_zjdu_options`;
RENAME table `wp_postmeta` TO `wp_zjdu_postmeta`;
RENAME table `wp_posts` TO `wp_zjdu_posts`;
RENAME table `wp_terms` TO `wp_zjdu_terms`;
RENAME table `wp_term_relationships` TO `wp_zjdu_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_zjdu_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_zjdu_usermeta`;
RENAME table `wp_users` TO `wp_zjdu_users`;
RENAME table `wp_termmeta` TO `wp_zjdu_termmeta`;

Options & Usermeta Table

Below two scripts will require some manual work. First, execute these scripts one after another, look for results. From the records, manually replace wp_ to wp_zjdu_ and save records.

Execute:

SELECT * FROM `wp_zjdu_options` WHERE `option_name` LIKE '%wp_%';

Action:

From the records, manually replace _wp to wp_zjdu_ and save records.

Execute:

SELECT * FROM `wp_zjdu_usermeta` WHERE `meta_key` LIKE '%wp_%';

Action:

From the records, manually replace _wp to wp_zjdu_ and save records.

Options & Usermeta Table

Options & Usermeta Table

Change Table Prefix in wp-config.php

WordPress needs to know that you have changed default _wp table prefix. Instruct WordPress to use new table prefix by changing wp-config.php file. Open your wp-config.php file which is located in your WordPress root directory. Change the table prefix line from wp_ to wp_zdju_ and save this file.

So the line would look like this:

$table_prefix = ‘wp_zdju_’;
Note: You can only change it to numbers, letters, and underscores.

wp-config.php

wp-config.php

Done:

You are done. Now, test your website, it should be working as usual. I suggest you take a back up of the database after susccessfully increasing security of your WordPress database by changing default database prefix in WordPress.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

Log in with your credentials

Forgot your details?