Skip to main content
phpMyAdmin Guide
CHAPTER 08 Beginner

How to Import and Export MySQL Databases | phpMyAdmin Migration

Updated: May 16, 2026
15 min read

# CHAPTER 8

Importing and Exporting Databases

1. Introduction

In professional software development, you never build a new feature directly on the live website. You build it on your laptop (Localhost). Once it works perfectly, you must move the files and the database to the live server on the internet (Production). But how do you physically move a database? You cannot just copy and paste the software. You must Export the local database into a portable text file, and Import it into the live server. In this chapter, we will master the life-saving skill of database migration.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand the .sql file format.
  • Export (backup) a complete database.
  • Import (restore) a database to a new server.
  • Troubleshoot common Import file-size limits.
  • Import CSV spreadsheet data into a database table.

3. Understanding the .sql File

When you export a database, phpMyAdmin does not give you a binary application file. It gives you a standard text file ending in .sql. If you open this file in Notepad, you will see thousands of lines of raw SQL code! It literally reads:
sql
123
CREATE TABLE users (...);
INSERT INTO users (id, name) VALUES (1, 'John');
INSERT INTO users (id, name) VALUES (2, 'Alice');

Exporting is simply asking phpMyAdmin to write down the exact SQL instructions required to rebuild your database from scratch on another machine.

4. Exporting a Database (Creating a Backup)

Let's backup our companydb to our laptop's "Downloads" folder.
  1. 1. Click companydb in the left sidebar. *(Crucial: Ensure the whole database is selected, not just one table!)*
  1. 2. Click the Export tab at the top of the screen.
  1. 3. Export Method:
  • *Quick:* Automatically dumps everything into a file. (Recommended for beginners).
  • *Custom:* Allows you to specifically select which tables to include, and whether to include the table structure (CREATE TABLE) or just the data (INSERT INTO).
  1. 4. Format: Ensure SQL is selected.
  1. 5. Click Go (or Export).
  1. 6. A file named companydb.sql will instantly download to your computer. Keep this safe!

5. Importing a Database (Restoring Data)

Now, imagine your live server crashed and the database was deleted. You must restore it from the .sql file you just downloaded.
  1. 1. Log into phpMyAdmin on the live server.
  1. 2. Important: An Import file usually does not create the database itself; it only creates the tables *inside* the database. You must first create a blank database (e.g., click New -> name it companydb).
  1. 3. Click on the newly created, empty companydb in the left sidebar.
  1. 4. Click the Import tab at the top of the screen.
  1. 5. Click Choose File and select your companydb.sql file from your computer.
  1. 6. Scroll to the bottom and click Import.
  1. 7. If successful, you will see a massive green box: *"Import has been successfully finished, 50 queries executed."* Your data is fully restored!

6. Exporting/Importing CSV Files

What if the HR department gives you an Excel spreadsheet containing 500 employee names and asks you to put them in the database?
  1. 1. Open the Excel file and click "Save As -> CSV (Comma Delimited)".
  1. 2. In phpMyAdmin, open the empty employees table.
  1. 3. Click the Import tab.
  1. 4. Choose the .csv file.
  1. 5. Under "Format", change the dropdown from SQL to CSV.
  1. 6. Check the box that says "The first line of the file contains the table column names" (if your Excel file has headers).
  1. 7. Click Import. The spreadsheet is instantly converted into database rows!

7. Mini Project: The Migration Workflow

Scenario: You built a WordPress blog on XAMPP (localhost). You bought a domain name and a Hostinger server. It is time to launch.
  1. 1. Localhost: Open XAMPP phpMyAdmin. Select wordpressdb. Go to Export -> Quick -> Format SQL -> Click Go. File downloads.
  1. 2. Production: Log into Hostinger's cPanel. Open the live phpMyAdmin.
  1. 3. Production: Create a blank database named livewordpressdb.
  1. 4. Production: Select it. Go to Import -> Choose the .sql file -> Click Import.
  1. 5. *Result:* Your local website is now live on the global internet!

8. Troubleshooting: The File Size Limit Error

The most common error in phpMyAdmin happens during Import. PHP has a strict security limit on how large an uploaded file can be (usually 2MB or 40MB). If your database backup is 100MB, phpMyAdmin will throw a fatal "File too large" error. The Fix:
  1. 1. Open your XAMPP installation folder.
  1. 2. Find the php.ini configuration file.
  1. 3. Open it in Notepad and find the line: uploadmaxfilesize = 2M.
  1. 4. Change it to uploadmaxfilesize = 128M.
  1. 5. Find the line: postmaxsize = 8M and change it to postmaxsize = 128M.
  1. 6. Restart the Apache server. You can now upload massive databases!

9. Common Mistakes

  • Exporting the Entire Server: If you don't click a specific database in the left sidebar first, and you just click the Export tab from the main homepage, you will accidentally export *every single database on the server*, including the internal MySQL system databases! When you try to import this into a new server, it will crash. Always click your specific database first.

10. Best Practices

  • Zip Compression: In the "Custom" Export options, look for the "Compression" dropdown. Select zipped or gzipped. Text compresses incredibly well. A 500MB .sql text file will shrink down to a 30MB .zip file, making downloading and uploading 10x faster!

11. Exercises

  1. 1. What file extension is universally used for database backup files containing raw SQL queries?
  1. 2. If you are trying to import an Excel spreadsheet into a table, what file format must you save the spreadsheet as first?

12. Database Challenges

You successfully exported my
database.sql from your local machine. You open phpMyAdmin on your live web host, select the Import tab, upload the file, and click Go. The server throws an error: No database selected. Explain the architectural mistake you made before clicking the Import tab. *(Answer: You forgot to select a target database. An .sql file usually only contains commands to create tables, not the database itself. You must click a specific blank database in the left sidebar BEFORE clicking the Import tab).*

13. MCQ Quiz with Answers

Question 1

When migrating a database using phpMyAdmin, what exactly does the generated .sql Export file physically contain?

Question 2

During a database Import operation, phpMyAdmin throws a fatal error stating the file exceeds the maximum upload size limit. As a server administrator, which exact PHP configuration file must you modify to increase the uploadmaxfilesize limit?

14. Interview Questions

  • Q: Describe the step-by-step procedure for migrating a local XAMPP database to a live production server. Include the resolution for the common "File too large" upload error.
  • Q: Explain the operational difference between the "Quick" export method and the "Custom" export method in phpMyAdmin. In what scenario would a DBA strictly require the Custom option?

15. FAQs

Q: My live database is 5 Gigabytes. Is it safe to Export this through the web browser? A: No! Web browsers will time-out and crash when downloading/uploading gigabytes of data. For massive enterprise databases, you should never use phpMyAdmin. You must log into the server via SSH (terminal) and use the mysqldump command-line tool.

16. Summary

You are now capable of deploying applications to the internet. By understanding the text-based nature of .sql files, compressing massive payloads, and navigating the Export/Import workflow, you can confidently migrate, backup, and restore entire database systems across the globe.

17. Next Chapter Recommendation

Our database is live on the internet! But right now, anyone who guesses our password has full access. We must lock it down. In Chapter 9: Managing Users and Permissions, we will learn how to create restricted user accounts to protect our data from hackers and accidental deletion.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·