A lot of my fellow bloggers and reviewers are using WordPress. Whether they started with it or have made the move from another (potentially inferior..) blogging tool, does not matter. What does matter is that many of these bloggers do not have a strong grasp of WordPress or how it works. It’s relatively easy to set up, out of the box, if you are not a demanding customer. However, what happens if you wish to move hosts, change your domain name or something goes wrong with your blog?
What is a database?
For a lot of people, this means turning to their hosts. That’s an okay solution. It usually works but it involves a middle man unnecessarily. If you have access to your databases, you can back up, move or restore your WordPress database without help from your webhost or anyone else.
Of course, if you don’t understand the concept of a database, you’re much less likely to try this (or, perhaps, to succeed). A database is a means of storing data in tabular format. When you, your host or a script installs WordPress, it edits the config file to instruct WordPress where to stores its information. Installation scripts such as Fantastic tend to create a new database and user, frequently with “WordPress” in the database and user names. However, if you are installing WordPress yourself, you can include multiple installations in the same database. I currently have 4 installations in a single database.
For the sake of this article, I will use the term “WordPress database” to simply refer to the actually data inside the database associated with your WordPress installation. Thus when I say you can backup or restore your database, I am saying you can backup or save all the pertinent data within the database.
And what sort of information is stored in your database? Posts, post meta (tags, categories), user information (names, levels), plugin information, widget contents, settings, comments, links and more. If I could somehow turn off my WordPress database for this blog, you would pretty much only see the header and background images.
Backing Up the Database
The WordPress Codex (which, I admit, I found ridiculously confusing at first) explains how to back up your WordPress database. By following this tutorial, you can save the contents of your database to your computer to upload at a later date, should the need arise. However, the article glances over how to access your database or PHP admin. Assuming you own your domain and have access to a control panel such as cPanel, H-sphere or a custom control panel (such as the one GoDaddy uses), you will first need to log into that control panel.
In my control panel, there is a link to phpMyAdmin on the index. I can click that, choose the account with access to my WordPress database and click the link. My control panel automatically logs me in. I can reach the same page in a slightly more complicated way by clicking “MySQL Server,” choosing my database, clicking the link to launch the admin panel and manually logging in. I frequently confuse my usernames and passwords so the first option is much easier. You likely have one or both of these options available to you. Then you may proceed with backing up the database.
The Codex tutorial explains that you will need to export the various tables in your database by checking the box next to the table. Typical installations use a prefix of “wp_.” Thus, you’ll see tables such as “wp_categories” or “wp_options.” If you do have multiple blogs or scripts installed to the same database, you will want to back up only the tables that belong to your blog. For example, of Sex and Love has a prefix of “wp_osal” to differentiate it from my other blog and script tables so I check only those tables to export.
This is the long and manual way. It gets the job done but so does the WordPress Database Backup plugin. It may even come with WordPress by default, now. I’m not sure because I use it on every single blog I own and for good reason! This plugin allows me to create an instant back up of my WordPress database directly from the WordPress dashboard.
Furthermore, I can use it to schedule back ups and I do. I schedule a weekly back up which the script e-mails to me. At my current posting rate, I would lose 2 posts at most if I only relied on this method. If you post more frequently, consider a daily back up.
WP DB Backup also allows the option to save your data to your webhost’s server and you should remember to check all the database tables that you want to save because the plugin only backs up the core tables by default. Tables created by other plugins are not included in this. I would lose information for my related posts and feed plugins if I did not check their tables. Note that you will see the list of all tables on the plugin management page. Thus, I see several closely named tables because I have multiple blogs in the same database. Pay attention when marking your tables for back up.
Restoring a Database
Once you have a copy of your database, you can do several things with it. You can restore your blog. This may be handy if your server crashes or someone hacks it. The Codex gives instructions on how to restore using PHPMyAdmin. But you probably want to drop all your extsing tables first to prevent errors.
You can use this same method to move to an entirely new host. Log into PHPMyAdmin or a similar tool in your new control panel. Create a new database and user, if one does not exist. For example, I have the option to add a database after clicking the “MySQL Server” link on the index. I can then choose to give access to a new or existing user. Import your WordPress database. When moving hosts or databases, you will want to perform this step before installing the actual script. Furthermore, you will want to install the script manually. This allows you to edit config.php to specify the new database and username. When you install WordPress, it will bring up your existing information.
You could also use this method if you wanted to switch domain names but remain on the same host. However, you could leave your existing database as-is and manually install WordPress on the new domain (after you add it to your hosting account) and enter the existing database credentials into your new config.php. Note that if you switch domain names, you will want to change the settings in your WordPress dashboard to reflect the new domain. Also note that you can work on your database or edit your WordPress installation even before a domain propagates. Simply use the dedicated IP, temporary URL or instant access domain name.
Blog Files
After extolling the virtues of the database, you may be curious how much necessary information is stored in the actual files that you can see via FTP or file manager. In the best case scenario, these files contain no necessary data for your blog. That’s right. None.
This scenario assumes you are capable of editing some files upon re-installation. If you know your database information, you don’t need to save config.php but it may be helpful. It’s easy enough to edit index.php if you place your WordPress installation files into a separate directly, which I suggest you do (http://domain.com/wp, for example).
The rule of thumb I would use for every other file is, if you edit it, save it.
Although widgets allow you to really customize your theme, many of us edit the actual code. Without my theme edits, you wouldn’t see my custom header, both sidebars, review images or ads. There are a million tiny other edits that only I would notice. If I were moving, I would save my entire theme folder inside the wp-content/themes directory.
Plug ins also have a folder of their own, within the wp-content folder. If the plug ins are currently and available as the repository, you really don’t need to back them up. If you have edited the plug ins or their folder contain data files, you can save them.
You may occasionally find important files within the wp-content folder itself. I have several files there that a plug in references to display my advertisements. The files that I would most likely forget to save are the images I have uploaded through the WordPress media tool. They exist in dated subfolders in the wp-content/uploads directory.
Of course if you have upload any other files to other locations, you will want to save them before moving hosts or domains. In the most complicated scenario, you will save the config.php, index.php, theme folder(s), plugin folder(s), uploads and user-created files.Uploading these and importing your WordPress database will recreate your blog as it was.
4 Comments to “All About the WordPress Database”
Trackbacks & Pingbacks
-
Tweets that mention All About the WordPress Database » of Sex and Love -- Topsy.com
-
Not Another Fucked-Up Situation – NEW BLOGGER INFORMATION – The Sin Doll
Ummm. okay.
Yeah, I think I’m gonna need this explanation in person. 😉
LOL Sure!