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
Release: 2024-11-13 06:58:02
Original
802 people have browsed it

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

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

Enter password directly (not secure):

mysql -u root -pPassword123 wp_users < wp_users.sql
Copy after login

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!

source:php.cn
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