How to Import SQL File into MySQL (3 Easy Ways 2026)

Learn how to import a SQL file into MySQL using phpMyAdmin, command line, or MySQL Workbench. Step by step guide for beginners — fix errors included.

How to Import SQL File into MySQL (3 Easy Ways 2026)

You have a .sql file sitting on your desktop. Maybe it is a backup from your old hosting. Maybe someone sent it to you. Maybe you just exported it from another database. Now you need to get it into MySQL — and you have no idea where to start.

This happens to almost every developer at some point. The good news is importing a SQL file into MySQL is not complicated once you know which method to use. This guide shows you three ways to do it — from the easiest click-and-go method to the most powerful command line approach.

Pick the one that fits your situation and follow the steps.


Before You Start — One Important Check

Before importing, always make sure your SQL file was created for MySQL. If the file was exported from PostgreSQL, SQLite, or another database type — it will not import cleanly into MySQL. You will get errors immediately.

If your SQL file came from a different database, you need to convert it to MySQL format first. DBConverter does this automatically in under one minute.

👉 Convert your SQL file to MySQL format free: https://dbconverter.site/sql-to-mysql

Once you have a MySQL-compatible SQL file, pick your import method below.


Method 1 — Import Using phpMyAdmin (Easiest)

phpMyAdmin is a web-based tool that comes pre-installed with almost every shared hosting plan — cPanel, Bluehost, Hostinger, SiteGround, and others. If you host your website on shared hosting, this is your fastest option. No terminal, no commands, just clicks.

Step 1 — Open phpMyAdmin

Log into your hosting control panel (cPanel). Look for the phpMyAdmin icon and click it. phpMyAdmin opens in a new tab.

Step 2 — Select or Create Your Database

Look at the left sidebar. You will see a list of your existing databases. Click the database you want to import into.

If you need a new database, go back to cPanel, open MySQL Databases, create a new one, then come back to phpMyAdmin and select it.

Step 3 — Go to the Import Tab

At the top of the page you will see tabs — Structure, SQL, Search, Query, Export, Import, Operations. Click Import.

Step 4 — Upload Your SQL File

Click Choose File and select your .sql file from your computer. Leave all other settings on their default values — they work correctly for most SQL files.

Step 5 — Click Go

Scroll to the bottom and click the Go button. phpMyAdmin reads your SQL file line by line and runs every command. When it is done you will see a green success message.

Your database is now imported. Click on your database name in the left sidebar and you will see all your tables with data inside them.

phpMyAdmin file size limit warning: phpMyAdmin has a default upload limit of 2MB to 8MB depending on your server settings. If your SQL file is larger than this, you will get an error. Use Method 2 or Method 3 for large files.


Method 2 — Import Using Command Line (Best for Large Files)

The command line method has no file size limit and is the fastest way to import large databases. It looks intimidating if you have never used a terminal before — but it is genuinely just one line of code.

Step 1 — Open Your Terminal

On Windows — press Windows key + R, type cmd, and press Enter. On Mac — press Command + Space, type terminal, and press Enter. On Linux — press Ctrl + Alt + T.

Step 2 — Navigate to Your SQL File (Optional)

If your SQL file is on your Desktop, type:

On Windows: cd Desktop

On Mac/Linux: cd ~/Desktop

This step is optional. You can also type the full path to your file in the import command instead.

Step 3 — Run the Import Command

Type this command and press Enter:

mysql -u your_username -p your_database_name < your_file.sql

Replace three things:

  • your_username — your MySQL username (usually root on a local computer)
  • your_database_name — the name of the database you want to import into
  • your_file.sql — the name of your SQL file

Press Enter. MySQL asks you for your password. Type it and press Enter again. The password will not show on screen as you type — that is normal.

MySQL now runs every command in your SQL file. For small files it finishes in seconds. For large files it may take a few minutes. When it is done you are returned to the command prompt with no error messages — that means success.

Step 4 — Verify the Import

To confirm everything imported correctly, type:

mysql -u your_username -p your_database_name

Then type:

SHOW TABLES;

You will see a list of all your tables. If they match what you expected — your import was successful.


Method 3 — Import Using MySQL Workbench (Best Visual Option)

MySQL Workbench is a free desktop application from Oracle. It gives you a full graphical interface for managing MySQL databases without using the command line. It is the best option for developers who want full control without memorising terminal commands.

Step 1 — Download and Install MySQL Workbench

Go to mysql.com/products/workbench and download the free version for your operating system. Install it like any normal desktop app.

Step 2 — Connect to Your Database

Open MySQL Workbench. Click the + icon next to MySQL Connections. Enter your hostname (usually localhost for a local database), your username, and click Test Connection to verify it works. Then click OK to save.

Double-click your connection to open it.

Step 3 — Run the SQL File

In the top menu click Server → Data Import.

A new screen opens. Select Import from Self-Contained File and click the folder icon to browse for your .sql file.

Under Default Schema to be Imported To, select your database from the dropdown or create a new one.

Click Start Import in the bottom right corner.

MySQL Workbench runs every command in your file and shows you a progress log. When it finishes you will see Import Completed in green.

Step 4 — Verify

In the left panel click the refresh icon next to your database. Click on your database name and expand it — you will see all your imported tables listed underneath.


Common Errors and How to Fix Them

Even when you follow the steps correctly, things can go wrong. Here are the most common import errors and their fixes.

Error: File is too large

This happens in phpMyAdmin when your SQL file exceeds the upload limit. Switch to the command line method — it has no size limit.

Error: Access denied for user

Your MySQL username or password is wrong. Double check your credentials. On a local computer the username is usually root and the password is whatever you set during MySQL installation.

Error: Unknown database

The database you specified does not exist. You need to create it first. In phpMyAdmin click New in the left sidebar. Via command line run CREATE DATABASE your_database_name; before importing.

Error: Table already exists

The database already has tables with the same names as in your SQL file. Either drop the existing tables first or import into a fresh empty database.

Error: You have an error in your SQL syntax

Your SQL file was probably exported from PostgreSQL or SQLite — not MySQL. The syntax is different. You need to convert it to MySQL format first before importing.

👉 Convert your SQL file to MySQL format: https://dbconverter.site/sql-to-mysql

Error: MySQL server has gone away

Your SQL file is too large and the import is timing out. Increase the max_allowed_packet setting in your MySQL config, or split the file into smaller chunks and import them one at a time.


How to Import a SQL File into a Remote Server

If your MySQL database is on a remote server — like a VPS or cloud server — the command line method still works. Just add the host flag:

mysql -h your_server_ip -u your_username -p your_database_name < your_file.sql

Replace your_server_ip with your server's IP address or hostname. Everything else works the same way.


Frequently Asked Questions

Can I import a SQL file without creating a database first?

No. MySQL needs an empty database to import into. Create the database first using phpMyAdmin or the command line CREATE DATABASE command, then import.

How long does it take to import a SQL file?

A 1MB file imports in seconds. A 100MB file takes a minute or two. A 1GB file can take 10 to 20 minutes depending on your server speed. The command line method is always faster than phpMyAdmin.

Can I import a PostgreSQL SQL file into MySQL?

Not directly. PostgreSQL SQL files use different syntax that MySQL does not understand. Convert the file to MySQL format using DBConverter first, then import it normally.

Is it safe to import a SQL file from someone else?

Be careful. A SQL file can contain any SQL commands including ones that delete data or create new users. Only import SQL files from trusted sources. Always import into a test database first before importing into your production database.

What is the difference between Import and Restore in MySQL?

They do the same thing — both run SQL commands from a file into your database. The terminology just differs between tools. phpMyAdmin calls it Import. Some tools call it Restore. The result is identical.

Can I import only one table from a large SQL file?

Yes. Open the SQL file in a text editor, find the CREATE TABLE and INSERT INTO statements for just that table, copy them into a new file, and import that smaller file instead.


Conclusion

Importing a SQL file into MySQL comes down to three choices:

  • phpMyAdmin — easiest, best for small files, no terminal needed
  • Command line — fastest, no file size limit, one simple command
  • MySQL Workbench — best visual option, great for developers

All three methods produce the same result — your SQL data inside MySQL, ready to use.

If your SQL file was created in PostgreSQL, SQLite, or another database and is giving you import errors — convert it to MySQL format first using DBConverter. It fixes all syntax differences automatically so your file imports cleanly on the first try.

👉 Convert any SQL file to MySQL format free: https://dbconverter.site/sql-to-mysql

👉 Need to go the other way? Export MySQL to CSV, PostgreSQL or SQLite: https://dbconverter.site/convert

Related Links

Ready to convert your database?

Use our free online converter — no account, no cost, files deleted in 2 hours.

Open the Converter ← Back to Blog