0

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.

5
  • that syntax looks fine, what output did it give? does the user you're specifying have the appropriate permissions for that database? Commented Apr 14, 2015 at 8:02
  • it is giving Syntax error Commented Apr 14, 2015 at 11:32
  • 1
    The syntax error is located in the sql file, not in the command (if the error message came from the mysql server). Check the file and correct any errors. Commented Apr 14, 2015 at 14:02
  • 2
    Your syntax is fine, there is probably an error on your SQL file. Try breaking it to smaller chunks to find the error. Commented Apr 14, 2015 at 14:11
  • Now, I used ' -uroot -proot database name ' and then 'source (path)\filename.sql ' and it is working..Now the problem which i am facing is that from the command prompt it is showing all the tables which are contaning in that file but when I am accessing it through MySQL it only shows the database name not the tables or any data in that Commented Apr 16, 2015 at 5:41

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

OP wants to import, which is done with the < character.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.