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
.sqlfile 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
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 ourcompanydb to our laptop's "Downloads" folder.
-
1.
Click
companydbin the left sidebar. *(Crucial: Ensure the whole database is selected, not just one table!)*
- 2. Click the Export tab at the top of the screen.
- 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).
- 4. Format: Ensure SQL is selected.
- 5. Click Go (or Export).
-
6.
A file named
companydb.sqlwill 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. Log into phpMyAdmin on the live server.
-
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).
-
3.
Click on the newly created, empty
companydbin the left sidebar.
- 4. Click the Import tab at the top of the screen.
-
5.
Click Choose File and select your
companydb.sqlfile from your computer.
- 6. Scroll to the bottom and click Import.
- 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. Open the Excel file and click "Save As -> CSV (Comma Delimited)".
-
2.
In phpMyAdmin, open the empty
employeestable.
- 3. Click the Import tab.
-
4.
Choose the
.csvfile.
- 5. Under "Format", change the dropdown from SQL to CSV.
- 6. Check the box that says "The first line of the file contains the table column names" (if your Excel file has headers).
- 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.
Localhost: Open XAMPP phpMyAdmin. Select
wordpressdb. Go to Export -> Quick -> Format SQL -> Click Go. File downloads.
- 2. Production: Log into Hostinger's cPanel. Open the live phpMyAdmin.
-
3.
Production: Create a blank database named
livewordpressdb.
-
4.
Production: Select it. Go to Import -> Choose the
.sqlfile -> Click Import.
- 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. Open your XAMPP installation folder.
-
2.
Find the
php.iniconfiguration file.
-
3.
Open it in Notepad and find the line:
uploadmaxfilesize = 2M.
-
4.
Change it to
uploadmaxfilesize = 128M.
-
5.
Find the line:
postmaxsize = 8Mand change it topostmaxsize = 128M.
- 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
.sqltext file will shrink down to a 30MB.zipfile, making downloading and uploading 10x faster!
11. Exercises
- 1. What file extension is universally used for database backup files containing raw SQL queries?
- 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 exportedmydatabase.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 themysqldump 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.