This is an old revision of the document!
In the previous Tutorial we covered how to perform a Database Backup. In this Tutorial we will discuss how to restore the database if you need to. Some reasons for restoring a database would be:
• database became corrupt • database inadvertently deleted • copying a database from one installation to another
Regardless of the situation, the process is always the same. Keep in mind, however, that when you restore a database you are effectively overwriting the existing database. Therefore, any changes to settings and templates, registrations that took place, listings that were entered, etc. between the time you performed your the back up until now will be lost. With that understanding, proceed as follows:
Step 1:
Before going any further you need to first prepare your backup file for importing. What this means is that you need to open up that .sql file and break it apart into smaller files. Why? Because the one single .sql file that you have now is more than likely too large for the server to handle all at one time. In other words, PHP on your server would "time out" before it finished running the entire file, leaving you with only a partially restored database. You can overcome this server limitation by breaking up the single file into several smaller files.
Ideally, you need to break the sql into 5 or 6 separate files. Simply open your .sql file and cut/paste a portion of the code into a new file. Save it and then repeat the process until you have created 5 or 6 separate files from the original .sql file. Your new files can be saved as any name you like. However, we recommend naming them by number so that you can maintain the order in which you upload them in a later step. ORDER IS IMPORTANT. For example, when you are finished you should have a set a files that look something like this: 1.sql, 2.sql, 3.sql, 4.sql, 5.sql, 6.sql
As long as you keep the files in order as described above, you don't have to worry about splitting up a large sql table between two files. If PHP finishes running a partial table in one file, it will then pick right back up and finish that table in the next file, if you upload them in the proper order.
important IMPORTANT: Ensure that your .sql file contains DROP TABLES for each table within the code. Failure to do so will result in error messages being displayed in phpMyAdmin. If you followed the steps in the "Backing up Your Database" Tutorial, then your .sql file should have drop tables in the code. See example below of what the first line in each table should look like.
droptable
Step 2:
Log in to phpMyAdmin.
note NOTE: The page layout and required steps may vary slightly depending upon the version of phpMyAdmin that is installed on your domain.
Step 3:
Select the database name you want to restore from the dropdown.
myadmin_7
Step 4:
When the screen refreshes you will see a list of tables that are currently present within the database you just selected. The same set of table names will display on both sides of the screen. (If this is a new database, or if you have previously 'dropped' the database tables, you will not see any.) You will see several tabs at the top of the screen. Click on the "Import" tab.
note NOTE: Older versions of phpMyAdmin will not have an "import" tab. Instead, you will need to click on the "SQL" tab, as it will be your only option for importing SQL.
myadmin_8
Steps 5 & 6:
You should now see a screen that looks similar to the image below. Click on the "Browse" button and upload the first your 5 or 6 .sql files you created in step 1 above using the popup window that appears. Once you have selected the file, click the "Go" button to upload the file. In a few moments you should see the screen refresh and the first set of SQL tables will be entered into the database. Repeat this process until you have uploaded all of your .sql files in order.
myadmin_9
Step 7:
You should now be able to log in to the software's admin panel using your admin username and password. If you are unable to, you can reset the admin username and password as described in the "Reset Admin Password" tutorial.
important IMPORTANT: Ensure that your .sql file contains DROP TABLES for each table within the code. Failure to do so will result in error messages being displayed in phpMyAdmin. If you followed the steps in the "Backing up Your Database" Tutorial, then your .sql file should have drop tables in the code. See example below of what the first line in each table should look like.