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

How to Import a Database into MySQL via Terminal?

Barbara Streisand
Release: 2024-11-25 20:52:12
Original
439 people have browsed it

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>
Copy after login

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>
Copy after login

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
Copy after login
mysql -u root -pPassword123 wp_users < wp_users.sql
Copy after login

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 of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template