Jump to content

Help Importing csv file to a specific column in a database table.


Recommended Posts

Hi all,

 

I have a table name states and I have 20 different states under this table.

 

I want to import csv file that contains names of cities that belongs to each states.

 

I am new to mysql and I am not such where to start. I have a web based application that I need to input these data. I have access to phpmyadmin through my hosting control panel.

 

Please help.

 

Thank you in advance for your help..

 

Regards,

 

Mark

Look into LOAD DATA INFILE. Something like

LOAD DATA INFILE "cities.csv" INTO TABLE `cities`
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' ESCAPED BY "\\"
    LINES TERMINATED BY "\n"
(`csvcity`, `csvstate`)
SET `city` = `csvcity`, `state`= `csvstate`

Hi again,

 

Where can I run this code? When I login into the phpmyadmin I can see the import button and when click , it ask for where to import data from but there is no place to place the code above. I have the csv files containing names of the cities for each individual states, each csv is unique to individual states. I know I have to import each csv 1 after the other for each states. But I cannot find where to run the code you provided above. Please help with abit of step by step.

 

Many thanks for your help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.