SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast MarkW78's Avatar
    Join Date
    Mar 2001
    Location
    Wellington, Ohio
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    0,13
    1,26
    2,39
    ...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,
    Mark

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Enthusiast MarkW78's Avatar
    Join Date
    Mar 2001
    Location
    Wellington, Ohio
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Kevin - I'm not sure how I missed that, but somehow I did. Thanks for pointing that out to me - it worked.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •