Load Data Infile
I need to take the data from a file and insert it into a MySQL table. Is this the best function to use?
If so, how do you get this to work right? I've tried several things and have looked at the docs at mysql.com but haven't found much help.
I did this:
mysql> LOAD DATA LOCAL INFILE '/path/to/file' INTO TABLE test;
My test data file was simply like this:
...and so on for about 10 entries. But when I look to see what actually went into the table, I see this:
| ID | A |
| 10 | NULL |
| 9 | NULL |
| 8 | NULL |
| 7 | NULL |
...and so on.
So how do I get it so that it puts column1 into ID and column2 into A? I'm sure this is a simple thing, but I'm just not sure how to do this.
Thanks for any help you can give,
Read the documentation (
http://www.mysql.com/doc/L/O/LOAD_DATA.html) again. You'll see that by default LOAD INFILE expects values to be terminated by tab characters, not commas. You'll need to add a FIELDS clause to indicate that fields are separated by commas.
Thanks Kevin - I'm not sure how I missed that, but somehow I did. Thanks for pointing that out to me - it worked.