Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to insert a tab delimited text file to a mysql database

by Withigo (Friar)
on Apr 16, 2006 at 23:59 UTC ( [id://543731]=note: print w/replies, xml ) Need Help??


in reply to How to insert a tab delimited text file to a mysql database

Since you said it's a one-time script, perl may be overkill for what can be done in one or two shell commands.
Create your table:
mysql -u [username] -e "use [database name];CREATE TABLE games (file v +archar(30) primary key, name text, description text, counter int)"
Populate it with the data file:
mysql -u [username] -e"use [database name];LOAD DATA INFILE '../data/g +ames/descriptions.txt' REPLACE INTO TABLE games FIELDS TERMINATED BY +'\t' LINES TERMINATED BY '\n' (file, name, description, counter)"
Replace [ database name ] with the database you are using, and [ username ] with your mysql username. What you are trying to acheive with $count appears to be handled automatically by the REPLACE part of the LOAD DATA command.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://543731]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-11-05 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (30 votes). Check out past polls.