How can I import a database with MySQL from terminal?

aneuryzm picture aneuryzm · Dec 28, 2010 · Viewed 759.1k times · Source

How can I import a database with mysql from terminal?

I cannot find the exact syntax.

Answer

anon picture anon · Dec 28, 2010

Assuming you're on a Linux or Windows console:

Prompt for password:

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

Enter password directly (not secure):

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

Example:

mysql -u root -p wp_users < wp_users.sql

mysql -u root -pPassword123 wp_users < wp_users.sql

See also:

4.5.1.5. Executing SQL Statements from a Text File


Note: If you are on windows then you will have to cd (change directory) to your MySQL/bin directory inside the CMD before executing the command.