Exporting .csv file into mysql server 2005 using script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exporting .csv file into mysql server 2005 using script.
# 1  
Old 03-04-2010
Exporting .csv file into mysql server 2005 using script.

Hi,
I have a .csv file created by a script with data in a tabular format.
I need to insert all the value into mysql database which is running in a different machine.

what is the command to export the .csv file into database using shell script.

Thanks in advance.
# 2  
Old 03-04-2010
I would probably read each line in and convert it to an SQL entry and apply all those entries to the database. If you're looking for a single shell command for that, you'll probably have a hard time. What have you tried? You might try contacting a group that focuses on mysql as opposed to shell scripting.
# 3  
Old 03-04-2010
You might want to consider this:

MySQL Data Import

Quote:
Do you know the problem? You are about to migrate an existing project to MySQL while looking for an appropriate conversion tool. Utility ImpSql can be the solution for this problem. It supports DBF and CSV file import as well as all usual memo file formats like FPT (FoxPro, Comix), DBT (Clipper) and DBV (FlexFile)
.
# 4  
Old 03-04-2010
Quote:
Originally Posted by ahamed
...
I have a .csv file created by a script with data in a tabular format.
I need to insert all the value into mysql database which is running in a different machine.

what is the command to export the .csv file into database using shell script.
...
If you have MySQL client installed in your machine, then you could use a nifty little tool called mysqlimport to import your csv file into a MySQL table.

Code:
$ 
$ # show the table "emp" in the MySQL database "test"
$ mysql -e "desc emp" -u test -ptest test
+-------+---------------+------+-----+---------+-------+
| Field | Type          | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| empno | decimal(10,0) | YES  |     | NULL    |       |
| ename | varchar(20)   | YES  |     | NULL    |       |
| sal   | decimal(7,2)  | YES  |     | NULL    |       |
+-------+---------------+------+-----+---------+-------+
$ 
$ # see if it's empty
$ mysql -e "select count(*) from emp" -u test -ptest test
+----------+
| count(*) |
+----------+
|        0 |
+----------+
$ 
$ # It is. Now show the contents of my csv file
$ cat /tmp/emp.dat
1000,SCOTT,7987.25
2000,JAMES,3489.00
3000,DAVID,5520.75
4000,PETER,6789.01
$ 
$ # Now use the sqlimport program to load data into the emp table
$ mysqlimport -u root -proot --fields-terminated-by="," test "/tmp/emp.dat"
test.emp: Records: 4  Deleted: 0  Skipped: 0  Warnings: 0
$ 
$ # Verify the successful load
$ mysql -e "select * from emp" -u test -ptest test
+-------+-------+---------+
| empno | ename | sal     |
+-------+-------+---------+
|  1000 | SCOTT | 7987.25 |
|  2000 | JAMES | 3489.00 |
|  3000 | DAVID | 5520.75 |
|  4000 | PETER | 6789.01 |
+-------+-------+---------+
$ 
$

HTH,
tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exporting .csv from home directory

I have created 2 .csv files in my home directory in unix and trying to export them to my machine. Can anyone tell me the script to export those? 1 file name is columns.csv (9 Replies)
Discussion started by: tinamiller
9 Replies

2. Emergency UNIX and Linux Support

How to connect Unix and Sql Server 2005?

Hi All Can any one please help me about How to connect Unix with Sql Server 2005 I want to do it urgently and i didn't find the way. (14 Replies)
Discussion started by: parthmittal2007
14 Replies

3. Shell Programming and Scripting

Unix with sql Server 2005

Hello All I am getting a problem.What i want to do is to connect unix(korn shell) and sql server 2005. But it is not happening. The task is to schedule a job using crown or something else that connect with sql server 2005 and run the query and save the result in a text file. (5 Replies)
Discussion started by: parthmittal2007
5 Replies

4. Shell Programming and Scripting

Remove duplicate commas after exporting excel file to csv

Hello everyone I'm new here and this is my first post so first of all I want to say that this is a great forum and I have managed to found most of my answers in these forums : ) So with that I ask you my first question: I have an excel file which I saved as a csv. However the excel file... (3 Replies)
Discussion started by: Spunkerspawn
3 Replies

5. Shell Programming and Scripting

Exporting data as a CSV file from Unix shell script

Friends...This is the first time i am trying the report generation using shell script... any suggestions are welcome. Is there a way to set the font size & color when i am exporting the data from unix shell script as a CSV file ? The following sample data is saved as a .csv file in the... (2 Replies)
Discussion started by: appu2176
2 Replies

6. Shell Programming and Scripting

TO execute .sql 2005 query file in shell script

Hi, I know in oracle a .sql file is called by @ <path> /<filename>. But how to call in sql 2005, I am opening the sql sessionwith sqsh, is there any command to execute there a .sql file (query in sql 2005) in K shell script. (0 Replies)
Discussion started by: n2ekhil
0 Replies

7. Shell Programming and Scripting

Script for exporting FS into non global server automaticaly.

Post has been removed. Prakash K :) (0 Replies)
Discussion started by: bullz26
0 Replies

8. AIX

IBM DB2 UDB to SQL Server 2005 Porting

Hi All, Am porting my application from AIX to Windows. As a part of this I need to port the Database in IBM DB2 UDB to SQL Server 2005. Is there any Guide/Doc/Article available on this? How to convert the stored procedures and physical data from DB2 to SQL Server 2005? Thanks in Advance (0 Replies)
Discussion started by: mvictorvijayan
0 Replies

9. Shell Programming and Scripting

exporting number into .csv file in text form (no other extra charc) from shell script

I have written a k shell program which is executing a sql and exporting data in numeric form like 0412323444 into .csv file. the problem i am facing is that , the data is coming in excel formatted in scientific form like 4.1+E08,while my requirement is to store data as such 0412323444 in excel ( no... (5 Replies)
Discussion started by: Deepak_Rastogi
5 Replies

10. Shell Programming and Scripting

Exporting text file data to csv

Could any one help me in basic shell script to export text file data to csv. I need to export only particular data from text file to csv column. I am a newbie to UNIX could anyone help me with sample script code (3 Replies)
Discussion started by: l_jayakumar
3 Replies
Login or Register to Ask a Question