1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DBWeinstein
  • 8,605
  • 31
  • 73
  • 118

2 Answers2

2

I used the following:

name   \N    2    4    2    100    emal@mail.com    o

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

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

DBWeinstein
  • 8,605
  • 31
  • 73
  • 118
1

"You can also discard an input value by assigning it to a user variable and not assigning the variable to a table column" read here

Example:

LOAD DATA LOCAL INFILE 'file.txt' INTO TABLE tablename (user_name, @skip, listings, connections, flags, days, email, suspend);
b.b3rn4rd
  • 8,494
  • 2
  • 45
  • 57