Reply
importing csv file into a table
Old 02-23-2008, 07:53 PM importing csv file into a table
Novice Talker

Posts: 10
i'm trying to write a script that will connect to a url and get the csv file there and then import it into a sql table every hour

i'm really new to SQL tho and i have no idea where to start with that

i'd really appreciate any help anyone could give me on this
namaah is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 02-23-2008, 08:17 PM Re: importing csv file into a table
joder's Avatar
Flipotron

Posts: 6,305
Name: James
Location: In the ocean.
You didn't say what database server so assuming mysql on linux.

I wish I could test it out right now but would be something similar to:

You would set up a cron job to do it every hour to run a script

Code:
#!/bin/bash
wget http://site.com/file.csv;
mysql -h database_host -u username -p -e database_to_load_into "LOAD DATA INFILE '/file.csv' INTO TABLE table_to_load_into FIELDS TERMINATED BY ','";
joder is offline
Reply With Quote
View Public Profile
 
Old 02-23-2008, 08:58 PM Re: importing csv file into a table
Novice Talker

Posts: 10
yeah, forgot about that ><

it's a mySQL database running on a linux server , and i'm using phpMyAdmin

sorry to be a pain but would you mind explaining that a bit more? i dont undertand that :/

i tried using it but it doesn't seem to like the web adress , it said there is an error and that " :// " is an unknown punctuation string
namaah is offline
Reply With Quote
View Public Profile
 
Old 02-23-2008, 11:03 PM Re: importing csv file into a table
joder's Avatar
Flipotron

Posts: 6,305
Name: James
Location: In the ocean.
You can't run it from within phpmyadmin. As far as I know, to do what you want, you have to subscribe to a shared server plan. Something that lets you run shell scripts.

wget is a program that runs on linux, not from within mysql. :// is part of the url just like http://www.google.com. wget retrieves the file in the url.
joder is offline
Reply With Quote
View Public Profile
 
Old 02-24-2008, 06:03 AM Re: importing csv file into a table
Novice Talker

Posts: 10
ah ok , thank you for helping with this

i have acess to the server to use linux commands aswell , i'll try doing that now
namaah is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 05:07 PM Re: importing csv file into a table
Novice Talker

Posts: 10
been away for a few days but tried that when i got back and i'm getting an error

Code:
ERROR 1102 (42000): Incorrect database name 'LOAD DATA INFILE '/Wallet.csv' INTO TABLE wallet FIELDS T'
i tired googling the error and didn't understand half the stuff i found so learning some linux commands but it's going to take a little while ><

how would i fix this error? it's definatly the right database name
namaah is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 05:16 PM Re: importing csv file into a table
joder's Avatar
Flipotron

Posts: 6,305
Name: James
Location: In the ocean.
Can you post the code you used?

Looks like you have something not in the right place or missing.
joder is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 05:50 PM Re: importing csv file into a table
Novice Talker

Posts: 10
sure thank you again

Code:
#!/bin/bash
wget url(changed because it contains passwords);
mysql -h localhost -u web35-shares -p -e web35-shares "LOAD DATA INFILE '/Wallet.csv' INTO TABLE wallet FIELDS TERMINATED BY ','";
namaah is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 06:08 PM Re: importing csv file into a table
joder's Avatar
Flipotron

Posts: 6,305
Name: James
Location: In the ocean.
Looks like web35-shares is both the user and database name. For the second time it is mentioned in the script, it needs to come before the -e
joder is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 06:16 PM Re: importing csv file into a table
Novice Talker

Posts: 10
yeah web35-shares is the username and the database name , tried it before the -e and that parts working now but also just noticed it's not getting the file correctly :/

the url is in this format

Code:
http://somewebsite.com/wallet.csv.aspx?user=00000&password=0000
and the files that are on my server are called

Wallet.csv.aspx?user=00000

also sorry to be a real pain but is there a way to get it to delete the old values and the old file when it dl's the new one every hour?

Last edited by namaah : 02-28-2008 at 06:29 PM.
namaah is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to importing csv file into a table
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14806 seconds with 13 queries