Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Backing up and restoring your database falls into the fact of life category of web professional chores. In this lesson, I'm going to walk you through the process of exporting your database completely, and then moving it to another location. I'll also discuss how you can restore the data to the same database. So, let's go to MAMP that I have open here and click Open the start page. So, I can get to phpMyAdmin. We will use this tool which is found on many web hosts and also accessible for you to download and install on your own systems at no cost.
So, I'm going to select my roux_blog database here. This is all the information that WordPress stores. You can see all the tables it creates. And should you so choose, you can easily choose a table such as posts and then select browse to see all the information. But what we're really interested in is going to roux_blog here and then exporting the entire database. Now, the latest version of phpMyAdmin has an option for choosing Quick and Custom.
The older versions only have the Custom one. So let's move to that, so you can see what the whole thing looks like. It's a slightly different screen, but it basically has all the same options. So, I'm going to select all the tables, make sure those are all selected. You have two options, one for saving as output to a file, and one for saving output as text. This time I am going to save the output as text. We'll keep the format as SQL. Just so you know, there are a ton of other options here. Then there's format specific options, including displaying comments, et cetera.
Typically, I find that just keeping the default options works well. So let's scroll down to Object creation options. Again, if you're moving your data to a different location, such as going from a development situation to a live server, keep the Object creation options just as they are, because what you are going to be doing is bringing your data into an empty WordPress installation. Let's continue scroll down. The Data dump options, again, keep these all the same. And when you get all the way down to the bottom, there is a little lonely Go button over here.
In older versions, it's on the right; in the newer versions, it's on the left. So I'll click Go. And pretty quickly, because we don't have a ton of data, you'll see all that information available to you. So to demonstrate the process here, what I am going to do is press Command+A to select everything and then copy it all. Now, I am going to go back to my localhost, choose Databases. Let's create another database. I am just going to call this one roux3. Click Create. Now, this is in the same situation as if you were just installing WordPress, and it was going to add all of its database tables and the like.
But instead of running through the WordPress installation, I'm going to select roux3 here, the database I just created, and go to my SQL tab. Now, you might think what you probably would do would be go to Import. You would only do that if you had saved the data as a file. Because I saved it as a text file and then copied it into memory, I can go right to my SQL tab. So I'm going to just paste in my copied SQL by pressing Command+V. Now, before we click Go, you actually want to go all the way up to the top of the information.
In this situation what I will need to do is to scroll over a little bit to the right so I can see the scrollbar and then grab it and go all the way to the top. It looks like that's fixed that. What I want to do is get to the name where it says the Database name. I am going to change that to whatever database that you're bringing it into. Now, we exported it from roux_blog, but we want to bring it into roux3. So, we'll add the 3 there, and now I can go ahead and click Go. Let's see what it did.
Now again, another difference between older and newer versions of PHP, with newer versions, you won't get a confirmation message that the data was imported. So just click the name of the database, and you'll see all of your tables in place. Older versions put up a mission accomplished type of statement. Now, we've bought our data in, but we are not quite finished. There are a couple of really critical chores. And the first one involves the wp_options table. So, select that. You want to change two values, the first one is right up top, and it's actually option_id number 1.
And if I go ahead and click on the Pencil Edit icon, you can see that what this is is the site URL. And you want to make sure to change the path, and I am just going to change this to my roux3 designation here. You want to make sure to change the path to whatever your new location is. If it's something that's on the website, you might want to make it something like this. Now, once you've got the website address up there, copy that, and then click Go. Now, you copy it because you're going to need to put it in another location, and you want to make sure that they're the same.
Of course, you want to make sure that they're both correct. Now, we need to go to the next page in order to see the next item that we have to change. So, click the next button that you see here, which is just the greater-than sign. We want to go to item 37 and make that edit there. So, this is the home URL. You recall in the General Settings category, we had both a site URL and home URL. We want to make that they're both the same. If you don't do this, you'll get into this kind of endless loop where when you try to log in, WordPress thinks that you're trying to log in to the original URL site and will keep redirecting you there. So, make sure you make these two changes.
I'll click Go to confirm that option. Now, there is one more thing that you may need to change, and that's the wp-config.php file. Let's head back to Dreamweaver. I am going to extend my Files panel, open it up all the way. I am going to go into the blog folder here. The file I'm looking for is the one that WordPress first created when you installed it, and it's called wp-config.php. Now, don't get confused, there is one that's wp-config-sample which is of course just an example of how the page is structured. Actually, it's got the information in it.
So, double-click on that, and I'll collapse my Files panel and then go into Code view. So basically, what you want to do is if you are changing the database name, database username, database password, or the database host, any of those things on your live installation, you want to make those modifications here and then upload it to the live site. This process that I've described is great for moving your database to a new location. But what about just restoring it to your database? The process is pretty much the same, except for one switch.
You want to be sure to throw in the export process. So, let's go back to our phpMyAdmin. And I am going to select the Database again and then Export. Now, let's go through the Custom Options one more time because I want to show you that one difference. And that's in the Object creation options section. You want to make sure to add Drop Table. What this will do is before it imports your data, it will erase any table that is there with the same name.
This ensures that you don't duplicate your data. If you forget to check the Drop Table option, and you've already exported your data, all is not lost. All you need to do at that point is go back to your Database, Check All, and then with All Selected, Drop. And that will clear out all of the tables so that you can properly import the data. It's very important to know how to manage your data. Many web hosts include the ability to back up your data on a regular basis. I encourage you to seek out and set up those options with any live WordPress site.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.