Adding an extra layer of security to your WordPress website is crucial in the face of potential SQL injections and other database-related attacks. One way to deter these types of attacks is to change your WordPress table prefix, which is set to 'wp_' by default.
Change the Table Prefix in wp-config.php
The wp-config.php file contains the configuration details for your WordPress installation, including the table prefix.
- Use SFTP to access the root directory of your WordPress site.
- Locate the wp-config.php file in the root directory and open it for editing.
- Once the file is open, look for the line of code that reads:
$table_prefix = 'wp_';
. This represents your current table prefix. - Replace
wp_
with your new desired prefix. Ensure your new prefix ends with an underscore_
. For example,$table_prefix = 'newprefix_';
. - Save your changes and close the file.
Change the Table Prefix in the Database
The next step involves renaming the tables in your database to match the new prefix.
- Sign in to your Atomic control panel and open phpMyAdmin.
- Select your WordPress database from the left sidebar and account for the tables with the
wp_
prefix. - Use a text editor to prepare the following query, replacing
newprefix
with your desired table prefix andyour_database_name
with the name of your WordPress database:
SELECT GROUP_CONCAT( CONCAT('RENAME TABLE ', table_name, ' TO ', REPLACE(table_name, 'wp_', 'newprefix_')) SEPARATOR '; ' ) AS batch_rename_statement
FROM information_schema.tables WHERE table_schema = 'your_database_name' AND table_name LIKE 'wp_%'; - In phpMyAdmin, select the SQL tab.
- Paste query you prepared into the SQL query box and select Go to run it.
- From the Extra options, select Full texts, then click Go.
- Select Copy to clipboard, paste the batch rename statement into the query box, then select Go.
Take a moment to look over the table names in the left sidebar to ensure they’ve been updated successfully.
Note: You may need to refresh the page or close and re-enter phpMyAdmin to see the update.
Update References to the Old Prefix
The final step is to update any stored data that references the old table prefix.
- Return to the SQL tab in phpMyAdmin.
- Enter the following, replacing the new and old table prefixes with your own:
UPDATE `newprefix_usermeta` SET `meta_key` = REPLACE(`meta_key`, 'wp_', 'newprefix_') WHERE `meta_key` LIKE 'wp_%'; UPDATE `newprefix_options` SET `option_name` = REPLACE(`option_name`, 'wp_', 'newprefix_') WHERE `option_name` LIKE 'wp_%';
- Select Go to run the query.
After submitting your updates, make sure to double-check that everything is functioning as expected.