Class 12 – Exporting & Importing Database Tables

Now that the course is over, you are free to keep using the class database at your own risk for as long as you like.  However, I will be making changes on the server in preparation for the next course, and these will most likely affect your database tables.  So I recommend you make a backup of your database tables, as explained here.  If you eventually set up your own hosting account with your own domain, you will be able to import these tables into the MySQL server, as detailed below.

Exporting your tables

To export a copy of your tables from the database, follow these steps:

Step 1. Select the database that holds the tables you want to export.

Do this by selecting “classdb” in the top left of the page.  This will take you to the “Database View” that will show you a list of all the tables in that database.

select database

select database

Step 2. Select the “Export” tab at the top of the “Database View” page

insert tab

export tab

Step 3. Select the tables you want to export

Do this by holding down the Control key and clicking the name of each database you want to select in the list. (On Mac, hold down the Command key instead of the Control Key).

select tables to export

select tables to export

The default settings should be fine for the rest of the controls on this part of the page.  The important points are to make sure both the Structure and the Data of your tables are getting exported.  So the checkboxes next to the words “Structure” and “Data” should be checked.

make sure Structure and Data are both selected

make sure Structure and Data are both selected

Step 4. Click the “Save as file” checkbox

At the bottom of the “Export” page, there is a checkbox next to the words, “Save as file”.  Make sure this is checked.

In this same area, you can optionally select to have the database export file compressed into a zip or gzip file.  This will make the file smaller, which is perfectly okay, but not necessary.  It’s your choice whether to compress the file or not.

save settings

save as file settings

Step 5. Click “Go” to export

At the bottom right of the “Export” page is the submit button with the word, “Go”.  Click it to complete the export.

go!

go!

Step 6. Save file

After a few seconds, you may see a dialog box asking you whether you want to “Open” or “Save” the file.  Make sure you select “Save”, and as always, make sure you remember which folder the file is getting saved into on your hard drive.

save file

save file

Congratulations!  You have successfully exported your tables.

Importing your tables

Assuming you have exported your tables from the classdb database, you may one day want to import them your own database on your own server.  Doing this is even simpler than exporting was.

Before you begin, you must have a database set up.

It’s important to remember that we only exported the tables, not the actual database.  So before you can import your tables, you will have to first create a database in which to import them.  You can call this database any name you want.  It does not have to be named, “classdb”, like the original database.

Most web hosts will have a control panel that allows you to create databases on your server.  Usually they disable this feature from phpMyAdmin.  As an example, here’s a screenshot of what the “Create a database” control panel looks like with Dreamhost, the host for the server we used in class.

create database in Dreamhost control panel

create database in Dreamhost control panel

Assuming you have created a database on your server, or you are using an existing database, here are the steps necessary to import your tables.

Step 1. Select the database that you want to import the tables into

Do this in phpMyAdmin by selecting your database name in the top left of the page.  This will take you to the “Database View” that will show you a list of all the tables in that database, if any exist.

select database

select database

Step 2. Select the “Import” tab at the top of the “Database View” page

import tab

import tab

Step 3. Select the file with the tables you want to import

The “Import” page will ask you for the “File to import”.  Click the “Browse” button to browse your hard drive for the file you exported.  Once that file is selected, you can leave all the other settings at their defaults.

file to import

file to import

Step 4. Click “Go” to import

Click the “Go” button to complete the import.

go!

go!

Congratulations!  You have imported tables into your database.

As a confirmation, you should now see the new table names show up on the left side of the page, where all tables are listed that are contained within the selected database.

list of tables

updated list of tables

Related posts:

  1. Class 8 – Using phpMyAdmin to administer a database

Tags: , ,

Leave a Reply