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.
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 inputmysql -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.
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
While this approach works, it has significant drawbacks:
--forceIf 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.
A dedicated database client like SQLPro Studio makes importing SQL files significantly easier and more reliable. Here's how:
.sql file from the file pickerDuring 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.
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.
Beyond SQL files, SQLPro Studio can also import data from:
All of these show progress during import and provide clear error reporting.
| 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 |
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.
For very large SQL files from the command line:
max_allowed_packet in your MySQL configuration if you encounter packet-size errorsSET 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.
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.
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.
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.
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