MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 13th, 1999, 02:25 PM
ThomasM
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Greetings,

I've been ghosting this board for awhile and
have decided there are a few bulbs here
brighter than my own, so I submit the
following quandry in hopes of finding some
illumination.

I'm developing some on-line mySQL managment tools. Most everything seems to work ok, except for the the "file data [local] infile" function.

Here's the input $sql and the output from $DBH->errmesg: (path names changed to protect the innocent. Lines are indented, non-indented lines are virtual wraps. Line
temination char is 'n')

#...input

$sql = "LOAD DATA LOCAL INFILE '$in_file' $slam_type INTO TABLE $tabl FIELDS TERMINATED BY '$split_type' LINES TERMINATED BY '$end_type'";

$sth = $dbh->query($sql) | | $error_message = $dbh->errmsg;
if ($error_message !eq "")(
print "Unable to add data to $tbl<br>";
print "Load Error Message: <br>$error_message<br>n";
}
#...end input

#...output

Unable to add data to PswdHash.
Load Error Message:
parse error near 'LOCAL INFILE '/root/web/client/local_dir/data_file.txt'
IGNORE INTO TABLE PswdHash FIELDS TERMINATED BY '|' LINES TERMINATED BY ' '' at line 1

#...end output

The data file exists and is readable by all. I tried running $sql through $DBH->quote() first, but no difference. I've tried it with
varying tables and data files, and with every quote/escape sequence I can think of. The tables import the data without a problem when
I load the data line by line using INSERT.

Any and all suggestions welcome...Thanks.


------------------
Tom
thomas@3dvr.net

Reply With Quote
  #2  
Old October 13th, 1999, 03:11 PM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thomas,

Check what version of MySQL you have. LOCAL is available on 3.22.6 or later.

It's likely you have an earlier version since the parse error starts at the LOCAL keyword.

Rod

Reply With Quote
  #3  
Old October 13th, 1999, 03:33 PM
ThomasM
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thanks Rod

I was hoping you would see my q.

Ok, will check, but where does that leave
me if the host isn't using 3.22.6? I
already tried it without LOCAL and get
Access Refused. Do I just have to resort to
reading the in_file line by line and using
an insert? (Not an enticing prospect with
a 40K row DB.)

Oh, and while you are (hopefully) handy,
do I need to €AðkPòk/á"Žó èñk¬l\òk<]Kattachments

Reply With Quote
  #4  
Old October 14th, 1999, 09:11 AM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Thomas,

You tried it without LOCAL? Where does the file reside? If it's on the host then you don't use LOCAL. There's some other things to note when it's on the host. The file has to reside in the database directory or be readable by all. Also, you must have the "file" privilege on the server host. (That's the biggest problem if you're using a shared hosting system, you probably don't.) This is exactly why the LOCAL keyword was added so they file could be loaded over the network without having to worry about these permissions on the host. First thing I'd do is make sure the permissions on the file are correct for read by all. CHMOD xxn where n is 4 or higher.

If the file is on your computer, try uploading and setting the permission as above and see if it works.

If you still get access refused, you probably don't have file privilege. (this is my problem on my shared system)

The only way I've found around this is to set up my own machine with mysql and use LOAD DATA INFILE on that machine. Then use mysqldump to dump out the table. This creates a text file with the SQL code to create the table and INSERT the data. If the table already exists on your host, just remove the CREATE line and leave the INSERTS.
Also, you'll need to add a USE dbname command at the top of the file.

Upload this file to your host. Then from the command line do this:

mysql -u username -ppassword < /path/to/file.txt

HTH

Rod

PS: I'm flattered you were hoping that I would see your question (if in fact you weren't trying to butter me up), however, I think your trust is misplaced. Many people out there know much more than I.

Reply With Quote
  #5  
Old October 14th, 1999, 12:40 PM
ThomasM
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Ok, I broke down and asked tech support
(at VARIO for reference) what the deal is.
They told me they don't support File Upload
for "security reasons" and that I should
load the data line by line with inserts.
This is clearly obfuscation since they do
allow multipart forms and fileloads, which
is the component of the process that is risky.

Your answer was most helpful. I get focus lock when I hit a problem and find it
difficult to take a step back and reappraise
the situation. Your suggestion of FDU at
a machine where I do have grant table file
permissions and then exporting them is a good example. I should have thought of that.
Unfortunately, it's not a workable long term
resolution because I am just a consultant
and have to leave them with a system that
allows them to update hundreds of huge tables
nearly in real time (they don't deal with much static data). It's the typical brick and mortar story. They know they need on-line
presence but they are clueless and easily led astray. For now, I will just load the tables with inserts (and watch their already pitfully overloaded servers gnash through
millions of unnecessary cgi loops. D'oh!) I have already started the process of convincing the client that it is cost effective to own and operate their own servers. Wait until they get the CPU time and BW bill from VARIO when they start using it.

Butter you up? Well, momma always said you catch more flies with honey than vinegar, but
my remark was completely subjective. I have read every post here for months. While I would have been just as happy to have heard from westb or our moderator or a number of other people, you are by far the most active poster and after two days of pulling my hair over this, I was hoping for a quick answer from a reliable source. You were my best bet.

I really appreciate your taking the time to
help with this. I am in your debt. Feel free to e-mail me if I can ever be of assistance.

T


------------------
Tom
thomas@3dvr.net

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Load Data Infile Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway