How to Import a SQL File into MySQL
Posted by Kyle Hankinson March 9, 2026
Importing a SQL file into MySQL is one of the most common tasks for database administrators and developers. Whether you're restoring a backup, migrating data between servers, or loading a schema for development, knowing how to efficiently import SQL files is essential. This guide covers several methods — from the command line to GUI tools — and explains why a dedicated database client can save you time and headaches.
Method 1: Using the MySQL Command Line
The most common way to import a SQL file is from the terminal using the mysql client:
mysql -u username -p database_name < file.sql
Here's what each part means:
-u username— your MySQL username (e.g.,root)-p— prompts you for your passworddatabase_name— the target database< file.sql— redirects the SQL file as input
Example
mysql -u root -p my_application < /path/to/backup.sql
After running this command, you'll be prompted for your password, and the import will begin.
Specifying a Host or Port
If your MySQL server is remote or on a non-default port:
mysql -u root -p -h mysql.example.com -P 3307 my_application < backup.sql
The Problem with Command-Line Imports
While this approach works, it has significant drawbacks:
- No progress feedback — you're staring at a blank terminal with no idea how far along the import is, especially painful with large files
- Errors halt everything — a single error stops the entire import unless you remember to add
--force - No easy way to inspect results — you have to reconnect and run queries to verify the data loaded correctly
- Encoding issues are silent — character set problems may not surface until you query the data later
Method 2: Using the SOURCE Command
If you're already inside the MySQL client, you can use the SOURCE command:
USE my_application;
SOURCE /path/to/backup.sql;
This is useful when you're already connected, but it shares the same limitations as the command-line approach — no progress indicator and limited error visibility.
Method 3: Using SQLPro Studio (Recommended)
A dedicated database client like SQLPro Studio makes importing SQL files significantly easier and more reliable. Here's how:
Import via Context Menu
- Connect to your MySQL server
- In the database tree, right-click on the target database
- Select Import → From SQL...
- Choose your
.sqlfile from the file picker - SQLPro Studio parses the file, splits it into individual statements, and executes them sequentially
During the import, a progress window shows real-time status updates so you always know how far along the import is. If any statement fails, you'll see the error immediately in an alert — no need to dig through terminal output.
Import via Drag and Drop
Even simpler: just drag a .sql file from Finder directly into the SQLPro Studio window. The file will open in a new query tab, ready to execute. This is perfect for quickly reviewing the SQL before running it, or for running specific parts of a large file.
Import CSV, JSON, and XML Too
Beyond SQL files, SQLPro Studio can also import data from:
- CSV files — with a column mapping interface that lets you match CSV columns to table columns, choose data types, and even create new tables on the fly
- JSON files — with the same column mapping and table creation options
- XML files — parsed and mapped into table rows
All of these show progress during import and provide clear error reporting.
Why Use a GUI Client?
| Feature | Command Line | SQLPro Studio |
|---|---|---|
| Progress indicator | No | Yes |
| Error visibility | Errors scroll by in terminal | Alert dialog per error |
| Preview before executing | No | Yes (opens in query tab) |
| Drag and drop | No | Yes |
| CSV/JSON/XML import | Requires separate tools | Built-in with column mapping |
| Character encoding | Manual --default-character-set flag |
Handled automatically |
| Available on | Terminal only | macOS, Windows, and iOS |
Handling Common Issues
Character Encoding
If importing from the command line and your SQL file contains special characters, specify the character set:
mysql -u root -p --default-character-set=utf8mb4 my_application < backup.sql
In SQLPro Studio, character encoding is handled automatically based on your connection settings.
Large Files
For very large SQL files from the command line:
- Increase
max_allowed_packetin your MySQL configuration if you encounter packet-size errors - Disable foreign key checks during import for faster loading:
SET FOREIGN_KEY_CHECKS = 0;
SOURCE /path/to/large_backup.sql;
SET FOREIGN_KEY_CHECKS = 1;
In SQLPro Studio, you can prepend SET FOREIGN_KEY_CHECKS = 0; to your import file or run it in a query tab before importing.
Database Doesn't Exist
Create the target database first:
CREATE DATABASE my_application;
Then import into it. In SQLPro Studio, you can right-click in the database tree and select Create Database before importing.
Method 4: Using mysqldump for Round-Trip Backup and Restore
The mysqldump tool creates SQL files designed to be imported back with mysql:
Export:
mysqldump -u root -p my_application > backup.sql
Import:
mysql -u root -p my_application < backup.sql
This is the standard approach for MySQL backup and migration, though SQLPro Studio also offers built-in export to SQL, CSV, JSON, and XML directly from query results or tables.
Summary
The command line works for quick, scripted imports, but for day-to-day database work, a dedicated client like SQLPro Studio provides a better experience: real-time progress tracking, clear error reporting, drag-and-drop convenience, and support for multiple file formats — all without memorizing terminal flags.
About the author — Kyle Hankinson is the founder and sole developer of SQLPro Studio and the Hankinsoft Development suite of database tools. He has been building native macOS and iOS applications since 2010.
Try SQLPro Studio — A powerful database manager for MySQL, PostgreSQL, Microsoft SQL Server, SQLite, Oracle, and Snowflake. Available on macOS, iOS, and Windows.
Download Free Trial View Pricing Compare