Home >Database >Mysql Tutorial >How to Import a Database into MySQL via Terminal?
Importing a Database into MySQL via Terminal
One may encounter a need to import a database into MySQL through the terminal. The process involves executing a command with specific syntax.
Syntax:
mysql -u <username> -p <databasename> < <filename.sql>
Explanation:
Variations:
If you want to enter the password directly (less secure), use the following syntax:
mysql -u <username> -p<PlainPassword> <databasename> < <filename.sql>
Example:
To import a database named "wp_users" using the "wp_users.sql" dump file with the root user and a password "Password123", execute the following command:
mysql -u root -p wp_users < wp_users.sql
mysql -u root -pPassword123 wp_users < wp_users.sql
Note: For Windows users, navigate to the MySQL/bin directory in the CMD before running the command.
Additional Resource:
Refer to the MySQL documentation: https://dev.mysql.com/doc/refman/5.6/en/executing-sql-statements-from-file.html
The above is the detailed content of How to Import a Database into MySQL via Terminal?. For more information, please follow other related articles on the PHP Chinese website!