Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2008
    Posts
    22

    Unanswered: load text file into database (was "Need help")

    Need Help,

    I have installed MYSQL SERVER and having problem to load a textfile in the DATABASE.

    I have a text file called 'pet' and using the following command.

    mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

    As my test file is in Destkop i am using the following path.


    mysql> LOAD DATA LOCAL INFILE '/C:\Documents and Settings\rkhanal\Desktop\pet.txt INTO TABLE pet;
    '> Lines TERNINATED BY '\n'; //--> Tells me " Unknown command '\n'.//
    '> \n';
    '>


    So the problem is why this line ('>) coming in the screen?
    What does that mean? What should i put in there?
    How do i see( What command i should use) that this text file is loaded in to my MYSQL database?

    i am folling the URL " http://dev.mysql.com/doc/refman/5.0/...ng-tables.html "


    FYI my test file looks like this:-


    Tom Ran Dog M 1993-02-04 \N
    CHuney Eva Dog F 1994-03-17 1993-02-04
    Slim Terry Cat M 1990-08-27 1986-03-05
    White John mouse F 1996-04-29 \N
    Slim Benny snake m 1996-04-29 1996-05-02
    Bowser Diane dog m 1979-08-31 1995-07-29



    Your Help will be highly Appriciated,

    Thanks,
    Ran

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try:
    mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet LINES TERMINATED BY '\r\n';

    the semi colon separates / temrinates a SQL LINE, so MySQL isn;t picking up the 'lines terminated by...'

    you also need to be consistent.. ie make sure every line is terminated by \N
    you also need to be precise, MySQL is case sensitive so you need to make sure your lines are terminated with the same character as you've told it \N, not \n
    you also need tomake sure your columns are separated by tabs.. im not sure these are

    HTH

  3. #3
    Join Date
    Mar 2008
    Posts
    22
    Thanks HTM

  4. #4
    Join Date
    Mar 2008
    Posts
    22
    HI ,

    Now that i am albe to move on a bit from where i was. But then again i don't know the command to see the loaded text table in to the MYSQL database. Can anyone help me what command should i type to see the loaded text table in the database.

    Thanks,

    Ran

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by rkhanal
    Can anyone help me what command should i type to see the loaded text table in the database.
    Code:
    SELECT * FROM pet
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Mar 2008
    Posts
    22
    Thanks Rudy. You been really very help full. Now i should be all ok with this.

Posting Permissions

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