Search code examples
mysqlprimary-keyauto-incrementload-data-infile

LOAD DATA LOCAL INFILe: loading data form text file auto incerment syntax


I'm trying to load data from a .txt file into mysql. The table looks like this:

+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| user_name   | varchar(10)      | NO   | MUL | NULL    |                |
| user_id     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| listings    | int(10) unsigned | NO   |     | 0       |                |
| connections | int(10) unsigned | NO   |     | 0       |                |
| flags       | int(10) unsigned | NO   |     | 0       |                |
| days        | int(10) unsigned | NO   |     | 0       |                |
| email       | varchar(30)      | NO   |     | NULL    |                |
| suspend     | tinyint(1)       | YES  |     | 0       |                |
+-------------+------------------+------+-----+---------+----------------+

when I load the data using LOAD DATA LOCAL INFILE how do I handle the user_id column? All the other items have data already. I'd like the database to assign the user_id's. Is that possible?

What should column under user_id look like in the text file?


Solution

  • I used the following:

    name   \N    2    4    2    100    [email protected]    o
    

    Each entry was automatically given the correct id in place of the \N.

    If there's a better way, please let me know.