If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > load text file into database (was "Need help")

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-17-08, 02:04
rkhanal rkhanal is offline
Registered User
 
Join Date: Mar 2008
Posts: 22
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
Reply With Quote
  #2 (permalink)  
Old 03-17-08, 03:43
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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
Reply With Quote
  #3 (permalink)  
Old 03-18-08, 02:22
rkhanal rkhanal is offline
Registered User
 
Join Date: Mar 2008
Posts: 22
Thanks HTM
Reply With Quote
  #4 (permalink)  
Old 03-18-08, 02:24
rkhanal rkhanal is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 03-18-08, 04:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 03-18-08, 20:48
rkhanal rkhanal is offline
Registered User
 
Join Date: Mar 2008
Posts: 22
Thanks Rudy. You been really very help full. Now i should be all ok with this.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On