Home > Database > Mysql Tutorial > How Do I Import a MySQL Database from the Terminal?

How Do I Import a MySQL Database from the Terminal?

DDD
Release: 2024-11-16 02:58:02
Original
560 people have browsed it

How Do I Import a MySQL Database from the Terminal?

Importing a Database with MySQL from Terminal

When working with MySQL, it can be necessary to import an existing database for various purposes. However, finding the exact syntax for importing a database from the terminal can be tricky.

Answer:

The syntax to import a database from the terminal using MySQL is as follows:

For Linux and Windows consoles:

  • Prompt for password:

    mysql -u <username> -p <databasename> < <filename.sql>
    Copy after login
  • Enter password directly (not secure):

    mysql -u <username> -p<PlainPassword> <databasename> < <filename.sql>
    Copy after login

Example:

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: If using Windows, change the directory (cd) to the MySQL/bin directory in the Command Prompt before executing the command.

Additional Resources:

  • [4.5.1.5. Executing SQL Statements from a Text File](https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html)

The above is the detailed content of How Do I Import a MySQL Database 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template