3

I'm using symfony, putty and other SQL commands seem to work fine but when I try to run an .sql file (of which there are many), the command line throws an error:

You have an error in your SQL syntax; check the manual ...

This is the command I'm trying to execute:

mysql < data/MySQLFile.sql;

I already used the use command on the proper database and tried using the full path, relative path, etc. Not sure what the problem is.

Here's the statement:

ALTER TABLE tablename
    ADD COLUMN `blahblah` varchar(10) NULL;
ALTER TABLE tablename
    ADD COLUMN `ggggggg` varchar(50) NULL;
7
  • 1
    What about showing us the SQL statement that generates the error? We can't see the SQL file from here. Commented Jan 15, 2013 at 22:40
  • Yeah I posted the sql statement that generates the error it's mysql < data/MySQLFile.sql; Commented Jan 15, 2013 at 22:57
  • No. That's not the statement. The statement that generates the error is somewhere in that SQL script. Commented Jan 15, 2013 at 22:59
  • 1
    The error message should tell you exactly which line of the file failed, and which part of the line had the problem. For example: ERROR 1064 (42000) at line 17 in file: 'MySQLFile.sql': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--I tried to do a comment but forgot the space after the dashes' at line 1 Commented Jan 16, 2013 at 0:04
  • 1
    Those two lines seem correct to me. Does that work when you run them standalone? Did you maybe forget a ; in the statement right before them? Commented Jan 16, 2013 at 7:57

3 Answers 3

14

if you want to execute through command line

mysql -u user -p < file.sql

and if you want to execute once logged in to mysql database. use any of the below commands.

source file.sql

or

\. file.sql

or

mysql db_name <file.sql
Sign up to request clarification or add additional context in comments.

1 Comment

After hours of searching this source file.sql was what I was looking for! Thank you!
2

Ok if you are in the mysql interface already type in:

\. /full path/to/file.sql

What I meant with full path is that you need to specify according to the current OS file system the location of the file. Just by putting data/ is not enough. For example if you are using MAC OS it would be: From the terminal and assuming is in Documents:

mysql < /Users/<yourusername>/Documents/file.sql

If you are already logged in mysql then type in:

\. /Users/<yourusername>/Documents/file.sql

If my tips don't help you, I will recommend you to go to this page:

http://dev.mysql.com/doc/refman/5.0/en/mysql-batch-commands.html To Find out more about this.

Comments

1

I think you just need to type 'source' before the path to the sql file. So you would have

mysql < source [fullpath]/MySQLFile.sql;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.