Vishal Varshney
Vishal Varshney

Reputation: 21

Import a .sql file to a MySql database

I want to import a SQL file through the command line interface.

I have tried the following code:

mysql -u username -p database_name < file.sql

This gives me a syntax error. Any help is appreciated.

Upvotes: 0

Views: 54

Answers (1)

Bram
Bram

Reputation: 2581

The syntax is:

mysql -u <username> -p <database> < textfile.sql

If you do it like this the file needs to be in the same directory you are currently in. If you know where the file is you can do:

mysql -u <username> -p <database> < /path/to/file/textfile.sql

Upvotes: 1

Related Questions