MySQL Upload SQL File: MySQL CLI vs phpMyAdmin for Importing Database Backups

Use the MySQL command line for large database backups. Use phpMyAdmin for small files, quick fixes, and people who hate black terminal screens. phpMyAdmin can hit PHP upload limits fast, and PHP lists upload_max_filesize with a default value of 2M [source: PHP]. So yes, your 600 MB shop backup may laugh at the browser and walk away.

TLDR: If your SQL file is tiny, use phpMyAdmin. It is visual and friendly. If your backup is big, use the MySQL CLI, like mysql -u user -p database_name < backup.sql. Example: a 480 MB WooCommerce backup may fail in phpMyAdmin because of upload and timeout limits, while the CLI can import it in a few minutes on the same server.

Two ways to import a MySQL backup

You have an SQL file. Maybe it is called backup.sql. Maybe it is called final final really final.sql. No judgment.

You need to put that file into a MySQL database. You usually have two common choices:

  • MySQL CLI, also called the command line.
  • phpMyAdmin, the web tool with buttons and tabs.

Both can work. Both can annoy you. One is better for big jobs. The other is better for quick jobs.

Option 1: Import with the MySQL CLI

The MySQL CLI is the tool you run from a terminal. It looks plain. It feels old school. But it is strong.

The basic command is:

mysql -u username -p database_name < backup.sql

Then MySQL asks for your password. You type it. The import starts.

If your file uses modern emoji or special characters, use this:

mysql -u username -p --default-character-set=utf8mb4 database_name < backup.sql

If your backup is compressed as a .gz file, you can often skip extracting it first:

gunzip < backup.sql.gz | mysql -u username -p database_name

That feels like wizard stuff. But it is just a pipe. One tool opens the file. The other imports it.

Why the CLI is great

  • It handles large files better. A 2 GB SQL file is not unusual for the CLI.
  • It avoids browser upload limits. No web form. No progress bar drama.
  • It is faster on many servers. The file can be imported right where MySQL lives.
  • It works well with automation. Cron jobs love it. Developers love it. Sleepy admins love it.

The catch is that you need server access. Usually SSH. If your host does not give you SSH, the CLI may be out of reach.

When the CLI feels annoying

It gives fewer hugs. Error messages can look cold. A typo can break the command. If you import into the wrong database, your day gets spicy.

So do this first:

  • Check the database name twice.
  • Make a fresh backup before importing.
  • Test on staging if the site matters.
  • Use SHOW DATABASES; if you are unsure.

Option 2: Import with phpMyAdmin

phpMyAdmin is the friendly web screen many hosts include in cPanel, Plesk, or custom dashboards. You click. You choose a file. You press Import. Nice.

Basic steps:

  1. Open phpMyAdmin.
  2. Select your database on the left.
  3. Click the Import tab.
  4. Choose your .sql file.
  5. Check the format is set to SQL.
  6. Click Import.

For small files, this is lovely. A 5 MB database from a local project? Easy. A blog backup with 30 posts? Go for it.

Image not found in postmeta

Why phpMyAdmin is great

  • It is visual. You can see tables, rows, and database names.
  • It is beginner friendly. No terminal needed.
  • It is good for small imports. Quick and simple.
  • It helps with spot checks. You can browse tables after import.

Honestly, it feels like phpMyAdmin was made for “just fix this one thing” moments. Rename a table. Import a tiny dump. Check if a user exists. Done.

Where phpMyAdmin gets cranky

Large imports are where the fun ends.

You may see errors like:

  • File too large
  • Maximum execution time exceeded
  • Allowed memory size exhausted
  • MySQL server has gone away

It drives me crazy when phpMyAdmin spins for 90 seconds, then drops a vague error like it did you a favor. The import may be half done. Or not done at all. Great. Very calming.

These failures often come from PHP settings:

  • upload_max_filesize
  • post_max_size
  • max_execution_time
  • memory_limit

You can raise those limits if you control the server. On shared hosting, you may not. That is when the CLI starts looking like the adult in the room.

Speed comparison: CLI vs phpMyAdmin

Speed depends on the server. Still, the pattern is clear.

  • 10 MB file: phpMyAdmin is fine. CLI is also fine.
  • 100 MB file: phpMyAdmin may work. CLI is safer.
  • 500 MB file: use CLI if you can.
  • 1 GB or more: CLI wins almost every time.

phpMyAdmin sends the file through the web server and PHP. The CLI talks more directly to MySQL. Fewer layers. Fewer places to trip.

Common import problems

1. The database does not exist

Create it first:

mysql -u username -p -e "CREATE DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

2. The backup contains CREATE DATABASE

Some dumps include database creation commands. Others do not. Open the first few lines of the SQL file and check. Do not edit a huge file in a weak text editor. It may freeze and sulk.

3. Foreign key errors

Some backups import tables in an awkward order. You can temporarily disable checks in the SQL file:

SET FOREIGN_KEY_CHECKS=0;
-- import statements here
SET FOREIGN_KEY_CHECKS=1;

Be careful. This is not a magic broom. It can hide real data issues.

4. Character mess

If names turn into weird symbols, the character set is wrong. Use utf8mb4 when possible. It handles more characters, including emoji. Yes, even the taco.

Image not found in postmeta

Which one should you choose?

Pick phpMyAdmin when:

  • The SQL file is small.
  • You do not have SSH access.
  • You want a visual tool.
  • You are making a quick import on a test site.

Pick the MySQL CLI when:

  • The SQL file is large.
  • The site is important.
  • You need speed.
  • You want fewer timeout errors.
  • You are restoring a full production backup.

A simple real world example

Say Mia runs a small online store. Her backup is 620 MB. She tries phpMyAdmin. The upload bar reaches 100%. Then the page times out. Classic betrayal.

Her host gives SSH access. So she uploads the file with SFTP. Then she runs:

mysql -u store_user -p store_db < store_backup.sql

The import finishes. No browser drama. No mystery page refresh. No hat thrown across the room.

Best practice before any import

  • Back up the current database first. Always.
  • Import into staging before production. If possible.
  • Check disk space. Large imports need room.
  • Match MySQL versions when you can. Old dumps can be picky.
  • Keep passwords out of command history. Let -p ask for it.

The final verdict

phpMyAdmin is the bicycle. Simple. Friendly. Great for short trips.

MySQL CLI is the truck. Less cute. More power. Better for heavy loads.

If you are importing a tiny SQL file, phpMyAdmin is perfectly fine. If you are restoring a serious backup, use the CLI. Your future self will thank you. Probably with coffee.

Thanks for Reading

Enjoyed this post? Share it with your networks.