How to Change the WordPress Database Prefix

In this step by step guide I would like to show you how you can change the database prefix on your WordPress website with the help of this query-generator tool. In case you’d prefer to know what every query means, you can find the detailed explanation in this tutorial.

And now let’s get started.

1. Open wp-config.php and be ready to change the database prefix there

First of all please open your wp-config.php configuration file which you can find just in your site folder (or just one level above). In that file please find the line like below and be ready to replace the table prefix mentioned there with a new one.

 * WordPress database table prefix.
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';

We will need to replace this line with our new prefix we’re going to use. For example you can use this randomly generated one:

$table_prefix = 'wp_hj87ka_';

Just refresh this page if you want a new random prefix to be generated.

Do not save the wp-config.php file yet! Before doing that we need to be ready to run the database queries. If you do it right away, you website will show WordPress installation for everyone who visits it until we run the queries from the next step.

2. Open phpMyAdmin and run SQL queries

Should I mention that before doing anything in your WordPress database it is better to have it backed up? I hope I shouldn’t.

On most of the servers and hosting providers phpMyAdmin is used to manage MySQL databases. So let’s find the link to it somewhere in your hosting conrtol panel. For me it looks like this in cPanel.

how to find phpmyadmin in cpanel
If cPanel is installed on your hosting you can find the phpMyAdmin tool pretty easily.

Then just select a database and run our queries on the “SQL” tab. And at the same time save the changes in wp-config.php file.

how to change WordPress database prefix in MySQL database
Just run these SQL queries to change a WordPress database default prefix.

As simple as that.