G3N Services

How to Change the wp_ Database Table Prefix in WordPress?

First, I will explain the “why” behind this action. It’s for enhancing database security. By changing the common wp_ prefixes to custom_, it becomes more difficult for malicious actors to gain access, for instance, to the wp_options table. Additionally, it prevents database conflicts when connecting it to another website.

Now, let’s discuss the first method to achieve this during installation:

We don’t read the description. We just replace it with our own.

The second method is when the website is already installed. We access the database management system (DBMS) and execute the following SQL query:

RENAME TABLE wp_commentmeta TO new_commentmeta;
RENAME TABLE wp_comments TO new_comments;
RENAME TABLE wp_links TO new_links;
RENAME TABLE wp_options TO new_options;
RENAME TABLE wp_postmeta TO new_postmeta;
RENAME TABLE wp_posts TO new_posts;
RENAME TABLE wp_terms TO new_terms;
RENAME TABLE wp_termmeta TO new_termmeta;
RENAME TABLE wp_term_relationships TO new_term_relationships;
RENAME TABLE wp_term_taxonomy TO new_term_taxonomy;
RENAME TABLE wp_usermeta TO new_usermeta;
RENAME TABLE wp_users TO new_users;
UPDATE new_options SET option_name = 'new_user_roles' WHERE option_name = 'wp_user_roles';
UPDATE new_usermeta SET meta_key = 'new_capabilities' WHERE meta_key = 'wp_capabilities';

If additional plugins are used, such as WooCommerce, you need to also include all the WooCommerce tables…

wp-config.php

/**

Prefix for database tables in WordPress.
You can install multiple sites in one database by using
different prefixes. Please specify only numbers, letters, and underscores.
*/
$table_prefix = 'custom_';

If you have any questions or suggestions, feel free to message me on Telegram @g3nnadych or WhatsApp.