To import a MySQL database from the command line, you can use the
mysql command-line client. Follow these steps to import a MySQL database:
- Open your command-line terminal or command prompt.
- Navigate to the directory where your MySQL dump file (usually with a
.sqlextension) is located. You may use the
cdcommand to change directories.
- Use the
mysqlcommand to import the database. The basic syntax is as follows:
mysql -u [username] -p [database_name] < [dump_file.sql]
[username]with your MySQL username.
[database_name]with the name of the database you want to import the data into.
[dump_file.sql]with the name of your MySQL dump file.
- After entering the command, you will be prompted to enter the MySQL user password. Enter the password for the specified MySQL user.
Here’s an example command:
mysql -u myuser -p mydatabase < mydumpfile.sql
- Press Enter to execute the command. The MySQL database will be imported, and you’ll see the SQL queries being executed in the terminal.
- Once the import is complete, you should see a confirmation message.
That’s it! You’ve successfully imported a MySQL database from the command line.
Please note that this method is suitable for small to medium-sized databases. For larger databases, you may want to consider other options, such as adjusting MySQL server settings or using tools like