+ Reply to Thread
Results 1 to 9 of 9

 

Thread: Import 600MB csv into database

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Sep 2007
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts


    Hi all

    I am a newbie and downloaded the 600mb datafeed from affiliate window. How to import this data into mysql?

    if i use "wget" and try to download the file from web directly , it isnt downloading the whole file and shows it is done. Importing retailer by retailer will take ages. and i could not find any way of doing this?

    Please help!!

  2. #2
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    Thats a big file, and will take a fair bit of memory on the server.

    You`ll probably end up having to upload the file to your server, and then write a script to open the file, and read it in line by line, and then inserting each line into the database as you go. Would be the most memory efficient way of doing it, although it would take a fair amount of time to run as thats a huge number of records to be inserted!

    You'll need to add:

    PHP Code:
    set_time_limit(0) and ignore_user_abort() 
    to your script to keep it running for that amount of time without timing out (although it's possible that the hosts settings may over rule that).

    I think your best bet would be to contact your host and get them to help you with it. Otherwise, you may need to split it into several smaller files, and then process each one.

    What exactly is it thats 600mb? Is it a file containing every single retailer on Affiliate Window or similar, as thats a huge amount of data! Assuming each record is 1/2Kb thats 1,228,800 records. If that is the case it would be much better to download all the files separately, and then write a loop to read in each file and add it.

  3. #3
    Registered User

    Status
    Offline
    Join Date
    Sep 2007
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks

    yes i have the file on the server but to use php for inserting it into database , need to allocate more then 2GB of memory which is not good at all.

    it is the sheet with the products of most of the retailers on affiliate window.

    is there anything like "insert into ...... limit rows" to do this or i need to break the file into small parts n do the same??

  4. #4
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    I think the best way would be to break it down into smaller chunks.

    You can retrieve product feeds from Affiliate Window through a URL, so you could create a PHP script that had a list of all the product feed url's, and then loop through them downloading the feed and importing it one by one. This way it would still be automated, but because you're working with much smaller files it won't use anywhere near as much memory.

    Alternatively, you could download the products in XML format, and their are parsers that will read only the current chunk of data into memory at a time. Although it would still take a long time to run, memory and resources wise it shouldn't use that much.

    It's the type of script that should be run from a command line though, rather than through a browser which is why it's probably going to be better to get your host to run it for you.

  5. #5
    Registered User

    Status
    Offline
    Join Date
    Oct 2003
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow - that's one hell of a niche site.

    You really, really don't want to do this. If the load fails fails for any reason, you're probably going to end up looking for a duff record in the middle of a 60mb file. Have you ever tried editing a 60mb file? Or maybe you'll just run out of resources somewhere along the line and have to start all over again, and again, and again. What if one merchant's data is duff and you need to exclude them?

    As previously suggested it would be much better to download merchant feeds to a folder and then write a script to loop round the folder adding each in turn.

  6. #6
    Registered User

    Status
    Offline
    Join Date
    Sep 2007
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot

    i will do what you have suggested.

    another thing is , is there any search engine that can be used for site having that much of data???
    i had a lot less products earlier n was using mysql full text search..

    but really need something better n fast.

    Please suggest.

  7. #7
    Registered User

    Status
    Offline
    Join Date
    May 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My advice is to use the LOAD DATA command from the mysql command line, this will avoid having to process it programatically (youll likely run into memory problems too by doing it this way..)
    www.forgettherest.com
    Quality Brands, Unrivalled Service

  8. #8
    Registered User

    Status
    Offline
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    another vote for LOAD DATA in mysql (or BULK INSERT in SQL Server...)
    its the only efficient way..

  9. #9
    tbp
    Registered User

    Status
    Offline
    Join Date
    Dec 2006
    Posts
    1,998
    Thanks
    0
    Thanked 22 Times in 22 Posts
    The only problem is that by the sounds of it mandeep is on a shared hosting account, so won't have access to the MySQL command line.

    Thats the reason I said for him to speak to his host, as they would need to do it for him.

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 21-01-07, 04:30 PM
  2. Relational or Flatfile Database?
    By Donk in forum Programming
    Replies: 19
    Last Post: 20-10-06, 12:51 PM
  3. convert from csv to tab delimited using PHP
    By andylink in forum Programming
    Replies: 2
    Last Post: 09-05-06, 06:00 PM
  4. Replies: 1
    Last Post: 04-04-06, 11:12 PM
  5. xml > csv into mysql with a sprinkle of php
    By morleymouse in forum Programming
    Replies: 4
    Last Post: 08-12-04, 03:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2