Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MySQL BULK INSERT problem

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
leke
LXF regular


Joined: Mon Oct 22, 2007 6:45 pm
Posts: 479
Location: Oulu, Finland

PostPosted: Tue Dec 29, 2009 2:58 pm    Post subject: MySQL BULK INSERT problem Reply with quote

Hi, this is the first time I've tried the BULK INSERT. I am getting this error message trying to insert a flat file into MySQL.
Code:
mysql> BULK INSERT TokiPonaDicTable
    ->
    ->     FROM '/home/leke/toki-pona_english.txt'
    ->
    ->     WITH
    ->
    ->     (
    ->
    ->         FIELDTERMINATOR = '::',
    ->
    ->         ROWTERMINATOR = '\n'
    ->
    ->     )
    -> ;
ERROR 1064 (42000): 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 'BULK INSERT TokiPonaDicTable

    FROM '/home/leke/toki-pona_english.txt'

    ' at line 1
Is there anything wrong in the above code?
Thanks.
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1381
Location: Loughborough

PostPosted: Tue Dec 29, 2009 5:23 pm    Post subject: Reply with quote

Hi leke...

It says a syntax error...

The error report says...

"
......near 'BULK INSERT TokiPonaDicTable

FROM '/home/leke/toki-pona_english.txt'

' at line 1
"

So take a look at your:-

toki-pona_english.txt

for `'`or `"` in at least the first line as this/these could be
causing the problem(s).

Something like Barry's for example may need to be something
like Barry\'s to prevent strange inverted comma errors and/or
words/characters that may cause Keyword/Esc_Character
etc errors.

Just guessing but worth a try...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
johnhudson
LXF regular


Joined: Wed Aug 03, 2005 2:37 pm
Posts: 767

PostPosted: Tue Dec 29, 2009 7:34 pm    Post subject: Reply with quote

I've never used BULK INSERT and I cannot immediately find a reference to it in info mysql. However, all the references to INSERT assume that you provide a value list before you provide the data.

AFAIK the only way you can import a data file without a value list is where your table layout exactly matches that of the CSV file (when you can use LOAD DATA INFILE 'filename' . . .)
Back to top
View user's profile Send private message
leke
LXF regular


Joined: Mon Oct 22, 2007 6:45 pm
Posts: 479
Location: Oulu, Finland

PostPosted: Wed Dec 30, 2009 8:59 pm    Post subject: Reply with quote

ahh, I originally googled this this problem for getting flat file info into a MySQL DB. I noticed the example used a CSV file, but thought I maybe I could use any text file if it was formatted in a usable way. It's like:
entry1 :: entry1
entry2 :: entry2
...and so on.
I noticed some of my entries are comma separated so replacing :: with , won't work, but my DB table is set up to have an id auto increment and 2 columns.

It's also interesting how you said it wasn't in the documentation. Maybe this example I found was for SQL (I have no idea if there are differences between SQL and MySQL -- I should google that too).

I'll check out LOAD DATA INFILE in the mean time and see if I can do it with this.

I also didn't think I had to escape quotation marks because i was working directly in the MySQL client. I'll give that a try too.
Back to top
View user's profile Send private message
johnhudson
LXF regular


Joined: Wed Aug 03, 2005 2:37 pm
Posts: 767

PostPosted: Thu Dec 31, 2009 8:09 am    Post subject: Reply with quote

The mysql default field separator in LOAD DATA INFILE is tabs; you can alter this with with FIELDS TERMINATED BY; if there are commas in the fields, you can enclose them with single or double quotes and add ENCLOSED BY.

As the mysql roadmap map says, they are moving towards ANSI SQL compliance but AFAIK they aren't there yet.
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast