Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error with mysql LOAD DATA ... from command prompt 1

Status
Not open for further replies.

josel

Programmer
Oct 16, 2001
716
US
I have a script:

Code:
mysql -u dbuser -ppassword -e "LOAD DATA INFILE '/appl/tmp/mysqlwr.txt'
        INTO TABLE dbfile.dbtable
        FIELDS TERMINATED BY ':'
        ESCAPED BY '\\'
        LINES TERMINATED BY '\n';"

When I run script, I get

Code:
PAGER set to stdout
ERROR 1064 at line 1: You have an error in your SQL syntax.  Check the manual that corresponds to yur MySQL server version for the right syntax to use near ''\'

    LINES TERMINATED BY ''' at line 4

I have browsed the and have not found an answer. I also searched through this forum - no luck!

Could you please identify what the problem might be with this "simple" script? This is my very first attempt ever and I've tried a number of combinations but have not been able to hit the nail on the head. :(

Thank you all in advance!


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
Well, as I continued to try changing things around, I finally got it to work

This is the new command:
Code:
mysql -u dbuser -ppassword -e "LOAD DATA  INFILE '/appl/tmp/mysqlwr.txt'
        INTO TABLE dbfile.dbtable
        FIELDS TERMINATED BY ':'
        LINES TERMINATED BY '\n';"

Why removing ESCAPED BY made a difference? I have no idea.
In the other hand, I wonder what if a \ is within text string ... What would happen now since I removed ESCAPED BY !!! ???

Regards;


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
I think the problem is that your command-line processor replaces '\\' with '\' and then executes the command, passing the '\' (which is invalid syntax) to MySQL. If you use '\\\\' instead, it would be replaced with '\\', which would be accepted.
 
Right you are Tony!

Thanks;


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top