Home >Database >Mysql Tutorial >How to import a database into MySQL from the terminal?

How to import a database into MySQL from the terminal?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-13 06:58:02742browse

How to import a database into MySQL from the terminal?

Importing a Database into MySQL from the Terminal

Importing a database into MySQL from the command line can be a useful and straightforward task. Here's how you can do it:

Syntax:

mysql -u <username> [-p] <databasename> < <filename.sql>

Parameters:

  • -u : Replace with the MySQL username.
  • -p: Optionally specify if you want to enter the password directly (not recommended).
  • : The name of the database to import into.
  • : The SQL dump file containing the database data.

Examples:

Prompt for password:

mysql -u root -p wp_users < wp_users.sql

Enter password directly (not secure):

mysql -u root -pPassword123 wp_users < wp_users.sql

Note: For Windows users, remember to navigate to the MySQL/bin directory in the CMD before executing the command.

Additional Resources:

  • [MySQL Documentation: Executing SQL Statements from a Text File](https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html# 批量命令中执行SQL语句从文本文件)

The above is the detailed content of How to import a database into MySQL from the 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