Change WordPress Database Prefix

in WordPress Security

As WordPress is an open source application all the database table names are known to everyone. If someone knows the name of your database table it makes it easier for them to guess a SQL injection script to delete all the records in the database table.

If you want to help secure your WordPress site you can do so by changing the prefix of your WordPress database tables. Changing the database table prefix means they can't guess your database tables.

The best time to change the table prefix is before you have installed your site, you can change the database prefix at either the installation page or changing the $table_prefix variable in the wp_config.php.

 * 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  = '12345abcde_';

If you change the WordPress database prefix after WordPress is installed then you will need to change some of the values that are added into the database by running the following SQL queries.

Database Changes

When you change the database prefixes in WordPress some people make the mistake of just changing the database table prefixes and they forget about WordPress using the table prefix to reference information in tables such as the options table or the user meta table.

If you look inside the wp_options table you will see a option_name value of wp_user_roles which stores what the different user roles are able to do. If you change the database prefix you will need to change this value in the SQL database to same as you prefix.

UPDATE `12345abcde_options` SET  `option_name` = '12345abcde_user_roles' WHERE  `12345abcde_options`.`option_name` = 'wp_user_roles';

There are also columns inside the wp_user_meta table which will store information about a specific user such as capabilities, user roles and new user settings, therefore you need to run a similar script to above

UPDATE `12345abcde_usermeta` SET `meta_key` = '12345abcde_capabilities' WHERE `meta_key` = 'wp_capabilities';
UPDATE `12345abcde_usermeta` SET `meta_key` = '12345abcde_user_level' WHERE `meta_key` = 'wp_user_level';
UPDATE `12345abcde_usermeta` SET `meta_key` = '12345abcde_user-settings' WHERE `meta_key` = 'wp_user-settings';

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To Newsletter

Get weekly updates to your email