Importing CSV file to mysql database using phpmyadmin

Discussion in 'Databases' started by bvfrezz, Jan 9, 2010.

  1. #1
    I am having some issues with importing a CSV file to one of my databases. The CSV file currently looks like this:

    Sea Link Inc 2481 Chandalar Dr Anchorage AK
    Sea Maiden Charters Anchorage AK
    Sea Star Stevedore Co Inc 2020 Anchorage Port Rd Anchorage AK
    Sea State One Marine 3020 Rampart Dr Anchorage AK

    There's the business name, address, city and state. I do not have column headings in the CSV file. When I upload the CSV file the aforementioned data is imported into the "business name" field. How can I get the second column in my CSV file to import into the "Address" field, the third column into the "City" field and so on in my table?

    Any help would be greatly appreciated. Thanks in advance for your comments.
     
    bvfrezz, Jan 9, 2010 IP
  2. basia

    basia Well-Known Member

    Messages:
    263
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    155
    #2
    I'm assuming you're using Mysql. You're going to have to do some pre-processing before import (a PERL script would be ideal for this). The field values need to be separated with a semicolon and they have to be within double quotes. Here's an example of a mysql record in csv format:

    "7";"1";"1";"0";;"login";"c5a337f86780400a0486f381453c1e8f";"something@gmail.com";"Somebody";"1241366894";"0";"0";"0";;;;
     
    basia, Jan 9, 2010 IP