Tips & Tricks

MySQL export/import databases over phpMyAdmin or command line

This tutorial is going to show you how to export/import MySQL database over phpMyAdmin or directly over the command line of your operation system.
Note: This is going to work on Unix based operation systems. It should work on windows as well but you will need to include the full path to the command as well.

In the beggining we will have to define sample MySQL database, username and password.
Username: root (by default the main username for MySQL is root)
Password: testpass123
MySQL database: exampledb
This is only an example. Let’s imagine that we have to export exampledb from a server and import it on another.

1. MySQL export/import databases over phpMyAdmin
– Export

In order to export the database over phpMyAdmin you need to login first and then pick up the database name from the navigation of phpMyAdmin in left.
Once you clicked on the database name you will see few tabs on the top of the page. Click on the Export tab. On the next screen you will see Export area and all the tables of the databse in a textarea. Click on the “Select All” hyper link and click on the Save as file checkbox. Then you can click on the Go button and it will ask you where to save the database. Save it on your hard drive and that’s it. Now you have a backup of your MySQL dababase.

– Import
Login phpMyAdmin, click on the database name from the navigation in left and then click on the Import tab. You will see File to import area and you should click on the Browse button. Bworse the file from your hard drive and then press Go. Congratilations! You have just imported the database 🙂

2. MySQL export/import databases over the command line
– Export
Once you are in the command line of your server execute the following command:
[root@UnixBox ~]# mysqldump -uroot -ptestpass123 exampledb > exampledb.sql
Note: Here you need to change the password, database and username if needed. Please notice that you should use the -u and -p option without spaces.
Now you have the database backup named exampledb.sql in the folder that you are located.

– Import
Importing of the database is as much easy as the export but you need to use just the mysql command. You need to have the MySQL database backup in the currenct location. then execute:
[root@UnixBox ~]# mysql -uroot -ptestpass123 exampledb < exampledb.sql
Note:
Here you need to change the password, database and username if needed. Please notice that you should use the -u and -p option without spaces.
That’s it. You have imported the MySQL database. Of course you can import phpMyAdmin exports in this way as well.

Have fun 😉

Leave a Reply