13 Nov
Posted by SE as Security, Wordpress
|
|
Print This Post
If your table prefix is “wp_” or “wp1_” or even “wordpress_”, then changing it will bring your Wordpress site security to a higher level.
By default Fantastico installation sets “wp_” as a prefix for each Wordpress table name. Since this is a known vulnerability, malicious users can exploit your data easily.
They specifically look for the wp_options table, because it will alter your Wordpress site look. Through wp_options they can set the url to redirect to their sites, leaving you the impression that your site was defaced.
If you already have a Wordpress site, take a look at either your config.php file or go to phpMyAdmin in cPanel to check your tables names.
// Entry in config.php showing wordpress table prefix used in the installation
$table_prefix = ‘wp_’; // Only numbers, letters, and underscores please!
Attackers can easily send malicious code using JavaScript injecting SQL targeting your wp_ based tables. To make your wordpress site really secure, change the prefix to something that is difficult to guess. I would pick something almost like a password, except you are limited here to only numbers, letters, and/or underscores.
You might want to check a plugin “wp prefix changer” written by Philipp Heinze for BlogSecurity.net. It should do the job for you. However, I had problems using it, and prefer the manual way which I already done for 2 blogs.
I strongly recommend you to do change the prefix, if it is plain wp_. Just follow the next 6 steps and you should be in good shape. I have tested these steps already with a WordPress 2.8 installation:
1- Take a backup
Since this is a change in your WordPress table structure, you will have to take a backup first.
In cPanel click on the “Backups” icon and click on “Generate/Download a full Backup” and proceed with a “Home Directory Backup”.
2- Edit your wp-config.php file and change
$table_prefix = ‘wp_’;
to something like
$table_prefix = ‘op2mro445_’;
3- Change all your your WordPress table names
Go to phpMyAdmin and choose your WordPress database. Click on sql menu item and enter the command to rename all your tables. Do it one table at a time.
Note: You might have more tables that start with “wp_” prefix, change all the tables.
Every time you paste one line into the SQL window, click on GO and see the table name change on your left. Keep changing the table names until all your wordpress tables have the new prefix.
Rename table wp_comments to op2mro445_comments;
Rename table wp_links to op2mro445_links;
Rename table wp_options to op2mro445_options;
Rename table wp_postmeta to op2mro445_postmeta;
Rename table wp_posts to op2mro445_posts;
Rename table wp_terms to op2mro445_terms;
Rename table wp_term_relationships to op2mro445_term_relationships;
Rename table wp_term_taxonomy to op2mro445_term_taxonomy;
Rename table wp_usermeta to op2mro445_usermeta;
Rename table wp_users to op2mro445_users;
4- Edit wp_options
Then you need to edit in the op2mro445_options table ( formaly wp_options ) table
Click on the table name link and then click on “Browse” menu item.
You will see all the data stored in that table. Look under the option_name column header and change wp_user_roles to op2mro445_user_roles.
You will be able to change it by clicking on the edit button for that record.
5- Edit wp_usermeta
And finally apply changes to op2mro445_usermeta formally ( wp_usermeta)
In phpMyAdmin highlight op2mro445_usermeta link and click browse menu.
Change every value under meta_key column header, that starts with the old prefix wp_ to the new prefix op2mro445_ the number or records might be different for your web site.
I had values wp_capabilities, wp_autosave_draft_ids, wp_user_level, wp_usersettings, and wp_usersettingstime for the field meta_key need, and changed each one to the new prefix: op2mro445_capabilities, op2mro445_autosave_draft_ids, op2mro445_user_level….
6- Done! Test your WordPress site now
It should be a lot more secure giving you the peace of mind to focus on blogging.
Oh, one more thing. Do another backup.
If I can be of any help, just let me know.
Popularity: 100% [?]
42 Responses
Jeremy
November 14th, 2007 at 7:29 am
1Awesome post Sherif.
Keep it up.
Fitz
November 15th, 2007 at 12:36 am
2Great post! I was having problems with Table Prefix changer and your method worked the first try.
Thanks!
sherif
November 15th, 2007 at 11:45 pm
3Thanks. I think it is safer to take the manual approach, because if you have an issue you would know where you stopped at.
I think using the plugin is riskier because if for any reason it stopped immaturely, you would not know what you have to clean.
Kaka
November 24th, 2007 at 5:26 pm
4ahem, this’s a nice post, but there’s something bugs? and/or problem in wp table prefix changer plugin. Some guys has reported if they can’t change their wp_prefix and always get error message: “Your User which is used to access your Wordpress Tables/Database, hasn’t enough rights (is missing ALTER-right) to alter your Tablestructure.”
actually, I had the exact same problem as them, and your method requires many time to do so, why? ’cause i’ve a bunch plugins which has been installed on my own blog, and of course it using wp_ prefix too, one of these are firestat.
but, i am successfully changing the default prefix (wp_) using my own method, see below:
01. backup your wordpress database (i’m using phpmyadmin) to an *.sql file.
02. open that *.sql file (make another copy first) using text editor, then find and replace all “wp_” prefix to “something_”.
03. now, drop all tables of your wordpress databases (don’t drop the database
)
04. import the *.sql file which has been edited before into your wordpress databases.
05. and lastly, edit your wp-config.php file and change the $table_prefix = ‘wp_’; to $table_prefix = ’something_’;
06. in my case, all plugins will be deactivaed automatically, so login to your blog admin panel, then activated your all plugin.
07. done !
yep, it work perfectly for me.. !
Sherif
November 25th, 2007 at 10:08 am
5Great idea, thanks for your comment.
Yup, your steps will work, however I think your approach is more risky, because the owner has to completely empty and rebuild all the tables in the database.
WP 2.3.1 Tables Which Must Be Renamed | Aufklarung Journal
December 9th, 2007 at 8:25 pm
6[...] A wordpress folks, Sherif Elsisi, has explained steps is done it, you can check on his blog here: tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress. But Sherif totally like Blogsecurity.net team, just described the wordpress primary tables that [...]
Rey
March 2nd, 2008 at 4:26 pm
7Great post brother. This helped me out of a serious bind.
Rey’s last blog post..Color Me Bad: Painting Again
Protect Your Neck: Securing Your Wordpress Blog | Rey's A Point
March 2nd, 2008 at 5:01 pm
8[...] your site just because they know you have the default info installed. This site here has the best instructions yet if you can’t get it to be changed [...]
9 SEO Security Tips for Wordpress to avoid being banned in Google | Antezeta Web Marketing
May 13th, 2008 at 3:40 pm
9[...] table names. There are several table prefix plugins which will do this for you, or you can follow manual instructions. Do note you may have problems with badly written plugins if they have hard-coded the table prefix [...]
9 Suggerimenti per migliorare la sicurezza di Wordpress ed evitare una penale da Google | Antezeta Web Marketing
May 14th, 2008 at 9:29 am
10[...] per definire il prefisso delle tabelle che faranno questo per te, oppure è possibile seguire le istruzioni manuali. È da notare che si possono avere problemi con le estensioni (plugin) scritte male se non [...]
» Blogging Tip: Is Your Blog Secure? Blog Marketing Journal
June 13th, 2008 at 6:25 pm
11[...] is very good six step guide to changing your table prefix at t-dot blog – simply follow the instructions carefully and you will safeguard your database tables. There is [...]
Typolight
September 6th, 2008 at 10:32 am
12Thanks, your nice post that helped me alot.
Chris
March 1st, 2009 at 8:37 am
13Hi,
Good post. I want to do this but I’m a bit hesitant as I have the eCommerce plugin installed and it’s got a ton of its own tables. They all start with wp_ as well – are you aware if these types of plugins use the table prefix setting in the options/config files mentioned above?
Thanks!
Sherif
March 1st, 2009 at 11:02 am
14Hi Chris
No guaranty, however any well written plugin should use the setting from the config files.
You can either try to uninstall the plugin and then after the change re-install it, or just check with the plugin author about it first.
Of course, don’t forget to take a good backup before starting any change.
Regards.
Chris
March 2nd, 2009 at 5:57 am
15Fair comments – thanks Sherif!
Mark
March 5th, 2009 at 5:39 am
16Awesome post!!
The auto option didn’t work and I did NOT want to do this manually.
YOU made it sooooo simple. Just follow the steps and you’ll be successful.
Thanks so much.
brenda
March 10th, 2009 at 6:49 pm
17I am so appreciative of this short tutorial. Someone told me change my tables and admin username but was not exactly sure how to do it. I found your site and followed your six steps.
thank you for the wonderful work~!
Sherif
March 12th, 2009 at 7:14 am
18Thank you for taking a look and your comment, if you have any other questions, please let me know.
Security Check - WordPress table prefix change adds more security | Blog Design Studio
May 21st, 2009 at 6:11 am
19[...] a. Manual way of changing – Sherif has posted a wonderful and detailed tutorial that allows you to change the table prefix in 6 simple steps. [...]
vg
June 21st, 2009 at 12:17 am
20Thanks! This is a great info, I’ve successfully changed my db from wp_
Miguel Guerreiro
June 21st, 2009 at 10:39 am
21Thanks, really easy tutorial. Well done.
8 Top Tips for Wordpress Theme development » James Whittaker
June 26th, 2009 at 11:04 am
22[...] this guide, I managed to change the database tables. However I could not log into the admin interface. To get [...]
mark edwards
July 3rd, 2009 at 4:06 pm
23used this and all works apart from my categories and tag cloud any ideas ?
mark edwards’s last blog post..How Can Increase In Interest Rates Of Banks Contain Inflation?
Sherif
July 5th, 2009 at 9:03 am
24Hi Mark
Try to change your theme to the default theme. If you don’t have the issue then the problem is in your theme.
Otherwise make sure you don’t miss any of the changes in editing the options table and the usermeta table.
I just tried it with a wordpress 2.8 installation and it worked with me.
Good luck.
Sherif
Increase Security in WordPress
July 17th, 2009 at 5:20 pm
25[...] http://tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress [...]
Chris
August 14th, 2009 at 2:41 am
26Hi Sherif. Thanks for the good info.
Can I just change the $table_prefix = ‘wp_’; in wp-config.php since I have not yet run the wp installer? Or do I also need to manually make the changes described in #3-5 on the link above?
I’m hoping that since I haven’t yet run the installer, I can make the change in the config file and it will automatically create the new db tables with the specified prefix.
Sherif
August 14th, 2009 at 7:34 am
27Chris
You are right, you can just change the prefix in the wp_config file before installing, and WordPress will take care of the rest.
I wrote this post for those who already installed WordPress with the default prefix.
Good luck.
D. Roberts
September 2nd, 2009 at 9:47 am
28Thank you! I luckily caught some php injected into my site and deleted it before it was used maliciously. Even saw the person come back to try to execute it and end up with file not found errors. They are blacklisted now and I used this tutorial to help lock it down to hopefully prevent this from happening in the future. Works like a charm! THANKS!
Sherif
September 7th, 2009 at 9:51 pm
29Thanks for writing. It helps to check the logs daily when you suspect something went wrong.
I am glad to be of help.
Radu
September 8th, 2009 at 8:14 am
30I did exaclty as you suggested here my website is working but I can’t login.
I get this: “You do not have sufficient permissions to access this page.”
What should I do?
Sherif
September 8th, 2009 at 10:16 pm
31Hi Radu
The changes highlighted here have nothing to do with logging in. Maybe you forgot to update the users table or the options table.
If you can’t figure it out, then I would recommend you to restore the backup.
Regards.
Sherif
Russ
September 16th, 2009 at 4:00 am
32Thanks for going into clear and simple detail in this post Sherif.
It’s a fact that hackers can via SQL injections compromise your database if they know your prefixes. Therefore the standard “WP_ ” prefix is an easy one to work over and there must be hundreds of thousands (millions?) of WP installs using Fantastico.
Having said that, I think that Fantastico is great and with latter and more improved versions of WP platform coming out (i.e the latest 2.8.4) that are incorporating more and more internal security then it will make things progressively safer.
For me,.. the changing if the DB table prefixes as you’ve indicated, and then saving your DB and attendant WP files prior to an admin panel “one-click” upgrade is adequate security. I think that there’s currently a bit too much hype and scare tactics being used as a means of enticing relative WP novices into using propriety install systems and memberships in order to build lists and customers.
Cheers to you Sherif and all your readers.
Russ
Sherif
September 20th, 2009 at 12:00 am
33Russ
I agree and thanks for writing.
Regards.
Sherif
Matt
October 29th, 2009 at 6:20 am
34Thank you very much! That was easy. I’d much rather do it manually if possible than add another plugin.
Paul
November 10th, 2009 at 6:32 pm
35I have Wordpress version 2.8.5 installed. When I changed the table prefix in the wp-config, it updated the database table names for me automatically. Is this some kinda accident, or have they fixed the problem in the latest version of Wordpress?!
Thanks for the great post by the way, was very clear and easy to follow.
Sherif
November 13th, 2009 at 8:10 pm
36Hi Paul
I think this is by accident, wordpress will never create tables for you unless you install it, maybe you installed by mistake.
Regards.
9 suggerimenti per migliorare la sicurezza di WordPress | Web Design
November 14th, 2009 at 12:04 pm
37[...] per definire il prefisso delle tabelle che faranno questo per te, oppure è possibile seguire le istruzioni manuali. Nota che si possono avere problemi con le estensioni (plugin) scritti male se non si riconosce il [...]
Peter
November 23rd, 2009 at 7:02 pm
38Hi Sherif – thanks for this, and the poststeps, often missing in other documents. I was apprehensive using the plugin and am happy this works as displayed (designed). I also had other tables and options in tables with the prefix, that worked well after the rename. Thanks.
Peter
Sabuj Kundu aka manchumahara
December 30th, 2009 at 6:08 am
39same thing can be done using this table prefix wordpress plugin http://blogsecurity.net/projects/prefix-changer.zip
thank you for your blog post too
medulin
January 7th, 2010 at 5:58 pm
40The wp security scan plugin can also do the job, but on most servers it does not work properly, so i think best way is to follow your recommodation.
How To Secure Wordpress Blog - An Exclusive Place for Developers and Designers
January 30th, 2010 at 4:22 am
41[...] something different, and leaving it as the default leaves you open to SQL injection attacks. Learn how to change your default WP database prefix in 6 easy steps here. 3. Your Wordpress version is hidden 4. That Wordpress database errors are turned off. Most web [...]
20+ Ways to Harden and Secure Your WordPress Blog | HighTechDad Blog
January 31st, 2010 at 2:56 am
42[...] tried) is SEOEgghead’s “WordPress Table Prefix Rename Plugin“. There are some manual steps available as [...]
RSS feed for comments on this post · TrackBack URI
Leave a reply
Welcome ...
My name is Sherif Elsisi and on this blog I share my knowledge, discovery and experience with hosting issues, Webmaster tools, security and usability.
About Me | Free blog setup | Value added Web Hosting
Categories
Archives
Links
Sponsors
Calendar
Select eBooks
Most Popular Posts
Latest Posts
Your Testimonials
News Headlines
Article Headlines
Web Hosting
Wordpress
Most Commented
Tdot – Blog hosted by TdotHost | BloggingPro theme by: Design Disease | Hosting and Blogging Guide is powered by WordPress