Results 1 to 2 of 2

Thread: Importing .cvs to MySql database -- phpMyAdmin

  1. #1
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Importing .cvs to MySql database -- phpMyAdmin

    I have a .cvs file that has a list of the building and room numbers
    here is what is in the test.cvs file
    Code:
    1	0111A
    1	0111B
    1	0111C
    2	0211A
    2	0211B
    2	0211C
    in the table called room_info it has two fields building and room

    when I insert the .cvs file it only inserts the first row of the .cvs file and it only inserts it into the building field... it leaves room blank.... and doesnt go any futher... no errors show up either... what am I doing wrong... I have never tried to import data before so I am lost here.. I tried to add "" around the input but that didnt help.. I also tried adding ; to the end of each line like 1 0111A ; that didnt work either...

    BTW room is the primary key... for the table

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Is it .CSV or .CVS. If it is .CSV then you should use comma as the delimeter. If the fields are delimeted using comma then it would look something like the following

    1,0111A
    1,0111B
    1,0111C
    2,0211A
    2,0211B
    2,0211C
    3,0789D

    If you want to import the data from a .CSV file issue the following command in the SQL Query manager area.
    Code:
    LOAD DATA INFILE 'C:\\test.csv' REPLACE INTO TABLE `test` 
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    ESCAPED BY '\\'
    LINES TERMINATED BY '\r\n'
    Here one of the most important point is FIELDS TERMINATED BY ',' if you try to import data which is not delimeted using comma then this will not work.

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
  •