What you need to know about the Wordpress database


Hacking the Database

Most of the time you needn’t worry about the database; WordPress will do that for you. There are database changes between versions sometimes, but program updates will take care of everything, and other than keeping a backup of your content the database can be leftto live its own life.

That being said, if things go wrong you may need to do some edits in the database to fix them. Common issues are password resets, weird URLs as a result of a failed move, domain name changes, and not forgetting the dreaded widget issue. Before moving on, you should remember that making alterations in the database is serious stuff. There are no undos here; what is deleted is deleted for good. Even if you know what you’re doing you should always make a fresh backup before altering anything at all. Should you not know your way around a MySQL database and PhpMyAdmin, then don’t mess with it until you do. You will break things.

Where Everything Is

Finding your way in the WordPress database is pretty easy. It consists of 10 tables, which in turn are full of content. Just browsing the database should answer most of your questions, and any edits can be made right then and there if you know what you’re after. Naturally, there is a full database description in the documentation (codex.wordpress.org/Database_Description) and you should consult that whenever you need to find something. The 10 main tables are:

All these tables are important, of course, but if you need to fix or change something directly in the database, chances are that it is in wp_options (for weblog settings, like URLs and such), wp_posts (for mass editing of your weblog posts), or wp_users (for password resets and such).

Fixing Issues by Hacking the Database

One of the more common issues with WordPress upgrades is the widgets going crazy, sometimes outputting only a blank page on your weblog. While this seems to be a lot less common these days, the upgrade instructions still state that you should disable all plugins and revert to the default theme. If you do, most likely you’ll never get that blank page.

However, should you get a blank page, it is probably a widget issue. A possible solution is to clean out the widgets in the database; they are hiding in the wp_options table. Exactly what you need to do and what the various widgets are called depends on what plugins you have, so tread carefully. Most likely the data is named in a way that seems logical compared to the plugins you use, and with that in mind you should be able to find what you’re looking for. It may sound a bit hazardous, but it is worth giving it a go should you encounter a blank screen on your weblog after an upgrade.

Another issue you may want to resolve in the database is changing or resetting a password for a user. You can’t actually retrieve the password from the database because it is encrypted and all you’ll see is gibberish, but you can change it to something else. Just remember that the passwords needs the MD5 treatment, which can be done through PhpMyAdmin or just about any MySQL managing tool you may use. Basically, what you do is type the new password in plain text, and choose MD5 for that particular field. You’ll end up with a new line of gibberish, which actually says what you typed in the first place. Again, if this sounds scary to you, don’t do it without exploring other solutions first!

Finally, you may want to mass edit your posts. Maybe you’ve got a new domain and want to change the source for all images you’ve used over the years, from olddomain.com/wp-content/ image.jpg to newdomain.com/wp-content/image.jpg, for example. There are plugins that will help you with this, so most of us should probably check them out first. If you’re comfortable with the database, though, you can run a SQL query to search for all these elements and replace them with the new ones. It could be some thing like this:

 UPDATE wp_posts SET post_content = REPLACE (
   post_content,
   'olddomain.com/wp-content/',
   'newdomain.com/wp-content/');

That would search the wp_posts table for any mention of olddomain.com/wp-content/ and replace it with newdomain.com/wp-content/. That in turn would fix all the image links in the example above. Nifty little SQL queries for batch editing can come in handy, but remember: there are no undos here and what’s done is done, so make sure you’ve got backups before even considering doing these things.

Legal Disclaimer

Our website is not responsible for the information contained by this article. Articleinput.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.

Note: This article was sent to us by: Orlando F. at 05132010

Related Articles

1. Wordpress Plugins and Functions PHP
Plugins and Functions PHP WordPress themes and plugins usually work pretty much by themselves, coming together only when it comes to implementing features. Th...

2. When to Use Wordpress functions php
When to Use functions.php When, then, is it really a good idea to use functions.php? I have a rule for that too: only use functions. php when the added function...

3. Are you using WordPress as a CMS
WordPress as a CMS Using WordPress for things other than blogging is something that comes naturally to a lot of developers today, but not so much for the ge...

4. Things to Consider When Using WordPress as a CMS
Things to Consider When Using WordPress as a CMS So you’re considering using WordPress as a CMS for a project huh? Great, and probably a good choice too...

5. Trimming WordPress to the Essentials
Trimming WordPress to the Essentials Usually, when doing work for clients or other people within your organization, you’ll have to think a little bit diff...

6. Wordpress Static Pages and News Content
Static Pages and News Content I touched upon static Pages and categories as a news model previously. It is truly a great tool whenever you need to roll out a ty...

7. Making Widgets a Little More Dynamic
Putting Widgets to Good Use Widgets and widget areas are your friends when rolling out WordPress as a CMS. It is perhaps not as important for the small and stat...

8. Wordpress The Header and Footer Templates
The Job Board The first special project we’ll work on is a job board. You have probably seen this kind of site already, where people and companies can pos...

9. When using TDO Mini Forms to build this solution
Receiving the Jobs There are numerous ways to receive the actual content for the job listings. The easiest way would be to just have people e-mail listings to y...