How to import text file to table with primary key as auto-increment

后端 未结 7 1655
清歌不尽
清歌不尽 2020-12-09 17:29

I have some bulk data in a text file that I need to import into a MySQL table. The table consists of two fields ..

  1. ID (integer with auto-increment)
  2. Na
7条回答
  •  失恋的感觉
    2020-12-09 18:21

    If the table columns do not match, I usually add "bogus" fields with empty data where the real data would've been, so, if my table needs "id", "name", "surname", "address", "email" and I have "id", "name", "surname", I change my CSV file to have "id", "name", "surname", "address", "email" but leave the fields that I do not have data for blank.

    This results in a CSV file looking like this:

    1,John,Doe,,
    2,Jane,Doe,,
    

    I find it simpler than the other methods.

提交回复
热议问题