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
.sql
extension) is located. You may use thecd
command to change directories. - Use the
mysql
command to import the database. The basic syntax is as follows:
bash
mysql -u [username] -p [database_name] < [dump_file.sql]
- Replace
[username]
with your MySQL username. - Replace
[database_name]
with the name of the database you want to import the data into. - Replace
[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:
bash
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 mysqlimport
or mysqldump
.