How to import a database with phpMyAdmin
Point phpMyAdmin at a SQL file and it rebuilds the database from it — provided the file is small enough for a single upload.
An import takes a SQL file — a plain-text script of table definitions and data — and runs it against a database, rebuilding whatever it describes. It is how you restore a backup, move a site between hosts, or set up a local copy of a live database. phpMyAdmin handles the common case well: a single SQL file, reasonably sized, imported through the browser.
Before you import anything
phpMyAdmin does not create the database for you as part of an import. Create an empty database and attach a user to it first — see creating a MySQL database and user — then import into that. If the database already holds data you need, back it up before importing anything into it, because a typical export drops and recreates each table it contains.
Step 1: open phpMyAdmin and select the database
phpMyAdmin is reached through the databases section of your control panel. Once open, the left-hand column lists every database on the account — click the one you are importing into so that its name is shown at the top of the main panel. Importing with the wrong database selected is the single most common mistake here, and it is easy to make when an account has several similarly named databases.
Step 2: go to the Import tab
Along the top of the main panel is a row of tabs: Structure, SQL, Import, Export and others. Choose Import, then Choose file and select the .sql file on your computer. Leave the format dropdown set to SQL — that is the format nearly every export produces, including phpMyAdmin's own.
Character set
There is a character set dropdown above the file selector, normally defaulted to utf8mb4. Leave it alone unless you know the file was exported with a different character set — mismatching it can turn accented characters, emoji or non-Latin scripts into garbled text on the way in, even though the import itself completes without an error.
Older utf8 in MySQL only stores three bytes per character, which cannot hold emoji or some less common characters. utf8mb4 stores the full range. If you are not sure which your file uses, utf8mb4 is the safer choice for a fresh import — see what utf8mb4 is and why it matters.
Step 3: run it and read the result
Click Go. For a small database this finishes in seconds. phpMyAdmin then shows either a green success message confirming the statements were executed, or a red error naming the exact line that failed. Do not treat a partial import as good enough — an error partway through usually means some tables were created and others were not, which produces confusing failures later rather than an obvious one now. Fix the reported error and re-run the import, having first dropped any tables it partially created.
The size and time limits that stop an import
phpMyAdmin's import is a normal file upload followed by a script that has to finish before your browser and the server both give up on it. Two limits matter:
| Limit | What happens when you hit it |
|---|---|
| Upload size | The file selector rejects the file, or the upload fails partway, before the import even starts. |
| Execution time | The page appears to hang and then shows a timeout or a blank result, even though the file uploaded successfully — the server gave up part-way through running the statements. |
Both limits are set at server level rather than something you can raise from within phpMyAdmin. If your file is comfortably under a few tens of megabytes, you will rarely notice either. If it is larger — a busy WordPress site's database with years of post revisions and log tables, for instance — plan for one of these two things to happen:
- Compress the file first. A
.sql.gzor.zipis often a fifth of the size of the raw SQL and phpMyAdmin decompresses it automatically during import. - If it is still too large once compressed, follow importing a database too large for phpMyAdmin, which covers splitting the file and importing over SSH instead.
After the import
Attach the database's user if you have not already — a fresh import does not change privileges, so an existing user attached before the import stays attached afterwards. Then point your application's configuration at the database and test it. If the application shows a connection error rather than your data, that is almost always a credentials or host mismatch rather than a problem with the import itself; see fixing a database connection error.
If you exported the file yourself, our guide to exporting a database covers the matching half of this job, including the export settings that make a later import go smoothly.
Frequently asked questions
Does importing overwrite what is already in the database?
Only where the SQL file tells it to. A typical export starts each table with DROP TABLE IF EXISTS followed by CREATE TABLE, which does replace that table entirely. Anything in the destination database that the file does not mention is left untouched.
Can I import a .zip or .gz file directly?
Yes. phpMyAdmin decompresses common formats — gzip and zip among them — during the import, so there is no need to extract the file yourself first. This also helps with the upload size limit, since compressed SQL is often a fraction of the original size.
Related reading
Turn a live database into a single portable SQL file, ready to back up, move, or hand to a developer.
How to import a database too large for phpMyAdminA file too big for a browser upload still has three practical ways in — compression, splitting, or the command line.
How to create a MySQL database and userEvery application needs a database, a user, and that user attached to the database — here is the order to do it in.
How to fix "Error establishing a database connection"A blank page with one line of text, and five possible causes. Here is how to tell which one you have, in the order worth checking.