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
- The shell reads the file path relative to the current folder when you use
<. - Very large files can hit server limits such as
max_allowed_packet. - To export a dump use
mysqldump -u USER -p mydb > dump.sql.