How To Change WordPress Database Prefix

WordPress uses a MySQL database to collect and store all the information. Your database is the brain of your WordPress site because it is the place where all your settings and posts are being stored.

Your WordPress database is also a target of all the bad hackers. The best way to protect your database is by changing the default WordPress database prefix.

Change Table Prefix Before Installation

You can’t perform this trick on your current WordPress installs, but you can do it with all your future WordPress installs or right now if you’re preparing to install a fresh WordPress copy.

Before installing WordPress, while configuring the wp-config.php file with all your database credentials, change the following part of the code:

Replace the wp_ prefix from above code to a random prefix, such as wp_kjd3qrsf_. You can generate random prefix for your database from random.org.

Change Table Prefix After Installation

You can also change your WordPress’ database prefix after installing your copy of WordPress. There are two ways of changing database prefix after installing WordPress, which are following:

Don’t forget to create a backup of your WordPress’ MySQL database!

With A Plugin

This is the best and the easiest way. If you’re non-technical guy then this way is just for you, also if you don’t like logging into your MySQL database account. You can use Change Database Prefix plugin for this task.

Just visit Dashboard > Settings > Change DB Prefix, and put down your new table prefix, and hit the Save button.

Change WordPress Database

Manually

Nerd, aren’t you? This part is not going to be hard for some tech people.

First, change the wp_ in the wp-config.php file with your custom table prefix. Login in to your MySQL database, click on the SQL button, which is located just right to the Structure button.

Just run the following SQL query with your own custom table prefix:

Now we need to change the options and usermeta tables to make everything work.

First enter the following SQL query:

Rename any option that begins with wp_ to our new prefix. We will do same with the usermeta table. Run following SQL command:

Rename all the tables here as well, just like the previous step.

Don’t forget to visit your WordPress’ back and front-end to check if it’s all working. If this broke your WordPress, then you can restore your MySQL database from the backup that we created earlier.