Home >Database >Mysql Tutorial >How to Import a Database into MySQL via Terminal?

How to Import a Database into MySQL via Terminal?

Barbara Streisand
Barbara StreisandOriginal
2024-11-25 20:52:12431browse

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:

  • -u : Specifies the MySQL username.
  • -p: Prompts for the password.
  • : Indicates the name of the database to import into.
  • < : Redirects the contents of the SQL dump file containing the database structure and data.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn