How to Import a MySQL Database
If you are restoring your MySQL database from an old backup, or if you are simply moving your Web site to a new server, you need to know how to import a MySQL database. There are two methods: using the phpMyAdmin GUI and using the SSH command line. The phpMyAdmin GUI is the preferred way to go because it is easier than the SSH command line. Follow these steps to learn how to import a MySQL database.
Instructions
-
Using PhpMyAdmin
-
1
Install phpMyAdmin software on your computer if it is not already installed. You can find phpMyAdmin software online at the phpMyAdmin homepage (see Resources below).
-
2
Log onto the phpMyAdmin page from your Web space. You will need the username and password assigned to you by your Web-hosting provider.
-
-
3
Select the database you wish to import the old data into from the drop-down Database Selection box on the left of the page.
-
4
Click the SQL tab toward the top of the interface.
-
5
Click the Browse button located toward the bottom of the page.
-
6
Find the .SQL file where it is saved on your hard drive, select it and click "Open."
-
7
Click the Go button. The data in your SQL file has now been imported into your database.
Using the SSH Command Line
-
8
Contact your hosting provider to gain SSH access.
-
9
Log into your Web space using an FTP client. You will need to know your username and password.
-
10
Find your existing .SQL database and upload it to your Web space using your FTP client. It doesn't matter where in your Web space you upload it to, as long as you execute the SSH command when you're in this folder.
-
11
Close your FTP program.
-
12
Log into your Web space using the appropriate SSH client. You will need the username and password assigned to you by your Web-hosting provider.
-
13
Enter the following into the command line, using your own database name, file name, username and password instead of the words in capitals.
mysql -uUSERNAME -pPASSWORD DATABASENAME < MYDATABASE.sql
For example, if my username was "silly," my password "computer," my database name "MyDB" and my file name "MyDBBack.sql," I would type:
mysql -usilly -pcomputer MyDB < MyDBBack.sql
-
1
Tips & Warnings
Use the phpMyAdmin GUI unless you absolutely need to use the SSH command line. It is much simpler.
Back up your databases regularly. Given the ease of importing and exporting your databases, you have no excuse not to.
This method is more complex than using phpMyAdmin.
Be careful probing around your Web space using the SSH command line. It's a powerful tool and you can cause yourself a lot of problems if you don't know what you're doing.