LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   mysql insert using bash script (https://www.linuxquestions.org/questions/linux-general-1/mysql-insert-using-bash-script-566824/)

venki 07-05-2007 08:44 AM

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

Guttorm 07-05-2007 09:03 AM

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 ',';

venki 07-06-2007 02:59 AM

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

Guttorm 07-07-2007 04:52 AM

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);


All times are GMT -5. The time now is 04:08 PM.