MySQL Import Database from SQL File in Linux

Last updated on Dec 30, 2019 in MySQL, Linux

During development environment setup we often have a database dump created with mysqldump and we need to import it from the command line. This is actually very easy:

In this example, we assume the dump file is named dump.sql and it is located in the same folder. In terminal, type:

$ mysql -u username -p database < dump.sql

We simple call the mysql client with a username and password, which is prompted. The database is the (empty) database we want the data to be imported from the dump.sql.

Note! If the dump.sql contains CREATE DATABASE command, we can omit the database argument completely, like this:

$ mysql -u username -p < dump.sql

What if the dump file is in .GZ format?

If the file is dump.sql.gz, it means it is compressed. To import database from .gz file, check this article: MySQL Import Database from .GZ File in Linux