How to import and export databases in phpMyAdmin

A database is the backbone of backend codes. It is a collection of tables that are logically related. There are two common kinds of databases that developers use today. These two common types are based on how they are structured and accessed. They are:

  1. Relational database
  2. Document oriented database

The former is also known as a SQL database, and the latter as a NoSQL database. This is based on the language of access.

There are a host of other database types like the graphical database, creative commons database, and so on.

It is common for those who write backend codes with PHP to use SQL databases, as they have high support from the language community. One commonly used SQL database among PHP developers is the MySQL database.

For easy development using MySQL and for easy integration with PHP, there is a support application called phpMyAdmin.

phpMyAdmin

This is a software tool that is free and was developed in PHP. It is used to carry out the administration of the MySQL database on the web. With phpMyAdmin, you can perform several operations like:

  • Database management
  • Creation and management of tables and columns, relations, and constraints
  • Users and permissions control

One very useful operation of phpMyAdmin is the ability to move databases across platforms that use the software. This action is known as the import and export of database tables. The steps for these import and export operations are described below.

Step 1

This step may seem trivial, but you have to be sure you have phpMyAdmin up and running. You can install it either as stand-alone from the phpMyAdmin official site or shipped with XAMPP or WAMPP, based on how you set up your development environment.

Additionally, you must confirm the database you wish to export or the database file you want to import. For example, in this shot, I will export the database in the image below.

For the import, I will be using a file called import.sql.

Step 2

Exporting

This step shows you how to successfully export the jumper database and its table.

  • Go to your phpMyAdmin and navigate to the screen shown in the above image.

  • Scroll through the options ribbon/bar at the top of the screen. Locate and click the export button, as shown below.

Step 3

Leave everything as shown in the image above, or you can make changes you prefer. For example, you can choose a different export format to change yours from SQL (which we are going to be using) to any other.

When that’s done, hit the GO button at the bottom left corner of the screen, as indicated in the image above.

This will cause your browser to pop up something like this.

Choose the save option and click OK. Now, our database has been successfully exported. Check the folder that holds your download files to see the file.

Step 4

Importing

The process to import is quite similar to the export process.

  • First, you have to know the database contained in the file to be imported. For our case, this is the import.sql file. The database file contained in it is the import database.

  • You will have to create a database in your phpMyAdmin, preferably with the same name as that to be imported. It can be any name, or you can even choose any existing database to import the new database tables into it.

Step 5

After deciding which database to use, locate the import option at the top of the screen, just as shown below. Hit the import button and the following screen will be displayed.

Step 6

Hit the browse key to choose your database file from your local storage. Then, hit the Go button indicated below. Wait a few moments and phpMyAdmin will display an “import successful” message. Once more, we have successfully imported a database and its tables.

Things to note

  • This operation is very useful when you wish to migrate from a local development environment to a production environment, especially using the CPANEL.

  • Importing a database simply entails importing all the tables of the database at a time. If you wish to import individual tables, follow the same steps as above, but always choose the table of interest.

  • If importing an individual table or the whole database at once, make sure the destination database does not have a table(s) with the same name as the table(s) to be imported, as this would lead to conflicts.

Free Resources