The standard WordPress install uses wp_ as a prefix for all tables in the database. By simply changing this prefix to something else, you will make your site a lot less vulnerable to hackers who attempt SQL injections and assume that you are using the generic wp_ prefix. On a brand new WordPress install, you will have the option to use any table prefix you want; you should change the default wp_ prefix to something custom.
If you would like to do this on a WordPress site that is already up and running, you can follow these steps:
- Make a database backup just in case you mess this up! It`s very important!
- Open wp-config.php and change $table_prefix = ‘wp_’; to $table_prefix = ‘anyprefixyoulike_’;
- Update the existing table names in your database to include your new prefix with the following SQL commands using phpMyAdmin or any SQL client such as MySQL Workbench:
rename table wp_commentmeta to anyprefixyoulike_commentmeta; rename table wp_comments to anyprefixyoulike_comments; rename table wp_links to anyprefixyoulike_links; rename table wp_options to anyprefixyoulike_options; rename table wp_postmeta to anyprefixyoulike_postmeta; rename table wp_posts to anyprefixyoulike_posts; rename table wp_terms to anyprefixyoulike_terms; rename table wp_term_relationships to anyprefixyoulike_term_relationships; rename table wp_term_taxonomy to anyprefixyoulike_term_taxonomy; rename table wp_usermeta to anyprefixyoulike_usermeta; rename table wp_users to anyprefixyoulike_users;
Warning! You will have to run a similar rename SQL query for any custom tables added by your app or plugins you are using.
Using SQL commands or a SQL client update any instance of wp_ in the prefix_options and anyprefixyoulike_usermeta tables and change any values like wp_ to prefix_ :
update anyprefixyoulike_options set option_name = replace(option_name,'wp_','anyprefix_'); update anyprefixyoulike_usermeta set meta_key = replace(meta_key,'wp_','anyprefix_');
Test out your site and make sure everything is working as it should.
If you don’t feel comfortable manually making these changes, there are some plugins that can change your table prefix for you: