LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 07-05-2007, 09:44 AM   #1
venki
Member
 
Registered: Sep 2006
Location: India
Distribution: suse10.2
Posts: 128

Rep: Reputation: 15
mysql insert using bash script


hi ,
THere is one csv file in that there are 100 lines.
i have to insert each line into mysql table?

plz give me the bash script!!
i am unble to solve..

eg
1.csv
1,2,3,4,5
1,3,4,6,8

there is mysql table .
i have to insert these values into table!!
plz help
 
Old 07-05-2007, 10:03 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,159

Rep: Reputation: 258Reputation: 258Reputation: 258
Hi

Take a look at:
http://dev.mysql.com/doc/refman/5.0/en/load-data.html

You don't write the command in bash, but in mysql. So something like:
mysql databasename
LOAD DATA INFILE '1.csv' INTO TABLE TheTable FIELDS TERMINATED BY ',';
 
Old 07-06-2007, 03:59 AM   #3
venki
Member
 
Registered: Sep 2006
Location: India
Distribution: suse10.2
Posts: 128

Original Poster
Rep: Reputation: 15
hi , its very useful data but..
i have table called rss
in that there are attributes
one , two ,three ,four,five
desc rss
-> ;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| one | varchar(255) | YES | | NULL | |
| two | varchar(255) | YES | | NULL | |
| three | varchar(255) | YES | | NULL | |
| four | varchar(255) | YES | | NULL | |
| five | varchar(255) | YES | | NULL | |
| six | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

where as my rss fields are
1,2,3,4,5
now i want to insert 1 in one,2 in two........

plz help
 
Old 07-07-2007, 05:52 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,159

Rep: Reputation: 258Reputation: 258Reputation: 258
Quote from the manual page:

Quote:
You can also discard an input value by assigning it to a user variable and not assigning the variable to a table column:

LOAD DATA INFILE 'file.txt'
INTO TABLE t1
(column1, @dummy, column2, @dummy, column3);
So perhaps:

LOAD DATA INFILE 'file.txt'
INTO TABLE rss
(one two, three, four, five, @dummy);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting special characters into mysql with bash script ihopeto Linux - Newbie 1 12-05-2006 01:46 PM
Bash script - how to add slashes to quotations for sending to MySQL? d60eba Programming 4 07-17-2006 03:16 PM
How do I insert timestamps in bash? spiffytech Linux - Software 5 01-27-2006 05:00 AM
Mysql in bash script acrors Red Hat 2 08-18-2004 10:11 PM
Bash script and mysql flashingcurser Programming 1 07-19-2004 04:35 AM


All times are GMT -5. The time now is 05:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration