MySQL Import File / Database Command

To import a MySQL database from a file, you can use the mysql command-line client.

Assuming that you have a MySQL dump file (which is a text file containing SQL statements that recreate the database), you can use the following command to import the file:

mysql -u username -p database_name < file.sql

Replace username with your MySQL username, database_name with the name of the database you want to import into, and file.sql with the name of the SQL file you want to import.

When you run this command, you will be prompted to enter your MySQL password.

Note that the < symbol is used to redirect the contents of the SQL file to the mysql command, which will execute the statements in the file and create the database.

If you want to import a compressed database file, you can use the zcat command to uncompress the file and then pipe it to the mysql command, like this:

zcat file.sql.gz | mysql -u username -p database_name

This will uncompress the file.sql.gz file and pipe the uncompressed contents to the mysql command to be executed.

In both cases, the mysql command will import the database and all of its tables, data, and other objects from the specified SQL file into the specified database.

Leave a Comment