Blog › MySQL · Published 2026-11-26

How to import an SQL file into MySQL from the command line

First create the target database if it does not exist:

mysql -u USER -p -e "CREATE DATABASE mydb"

Then import the file:

mysql -u USER -p mydb < dump.sql

Or from inside the MySQL client:

mysql -u USER -p mydb
mysql> source /path/to/dump.sql

Notes

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles