importing a CSV into phpmyadmin

后端 未结 4 1278
情深已故
情深已故 2020-11-29 08:25

I have a CSV that looks like this,

candidate_id,show_on_site,first_name,surname,gender,DOB,showdob,Location,height,eyes,hair_colour,hair_length,accents,union         


        
相关标签:
4条回答
  • 2020-11-29 08:39

    This is happen due to the id(auto increment filed missing). If you edit it in a text editor by adding a comma for the ID field this will be solved.

    0 讨论(0)
  • 2020-11-29 08:43

    Using the LOAD DATA INFILE SQL statement you can import the CSV file, but you can't update data. However, there is a trick you can use.

    • Create another temporary table to use for the import
    • Load onto this table from the CSC

      LOAD DATA LOCAL INFILE '/file.csv'
      INTO TABLE temp_table
      FIELDS TERMINATED BY ','
      LINES TERMINATED BY '\n'
      (field1, field2, field3); 
      
    • UPDATE the real table joining the table

      UPDATE maintable
      INNER JOIN temp_table A USING (field1)
      SET maintable.field1 = temp_table.field1
      
    0 讨论(0)
  • 2020-11-29 08:44

    In phpMyAdmin v.4.6.5.2 there's a checkbox option "The first line of the file contains the table column names...." :

    0 讨论(0)
  • 2020-11-29 08:46

    In phpMyAdmin, click the table, and then click the Import tab at the top of the page.

    Browse and open the csv file. Leave the charset as-is. Uncheck partial import unless you have a HUGE dataset (or slow server). The format should already have selected “CSV” after selecting your file, if not then select it (not using LOAD DATA). If you want to clear the whole table before importing, check “Replace table data with file”. Optionally check “Ignore duplicate rows” if you think you have duplicates in the CSV file. Now the important part, set the next four fields to these values:

    Fields terminated by: ,
    Fields enclosed by: “
    Fields escaped by: \
    Lines terminated by: auto
    

    Currently these match the defaults except for “Fields terminated by”, which defaults to a semicolon.

    Now click the Go button, and it should run successfully.

    0 讨论(0)
提交回复
热议问题