Import CSV to MySQL

后端 未结 3 2128
慢半拍i
慢半拍i 2020-11-27 04:01

I have created a database and a table. I have also created all the fields I will be needing. I have created 46 fields including one that is my ID for the row. The CSV doesn\

相关标签:
3条回答
  • 2020-11-27 04:22

    You can have MySQL set values for certain columns during import. If your id field is set to auto increment, you can set it to null during import and MySQL will then assign incrementing values to it. Try putting something like this in the SQL tab in phpMyAdmin:

    LOAD DATA INFILE 'path/to/file.csv' INTO TABLE your_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' SET id=null;
    
    0 讨论(0)
  • 2020-11-27 04:29

    Please look at this page and see if it has what you are looking for. Should be all you need since you are dealing with just one table. MYSQL LOAD DATA INFILE

    So for example you might do something like this:

    LOAD DATA INFILE 'filepath' INTO TABLE 'tablename' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (column2, column3, column4);
    

    That should give you an idea. There are of course more options that can be added as seen in the above link.

    0 讨论(0)
  • 2020-11-27 04:33

    be sure to use LOAD DATA LOCAL INFILE if the import file is local. :)

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