Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-25-2010, 05:50 AM   #1
LQ Newbie
Registered: May 2010
Posts: 3

Rep: Reputation: 0
Write a script to extract information from db tables


I want to write a script that will extract information from a db table and store that information to a csv file.

Basically, I have imported data into a table, I want to save this data to a csv file for later processing.

How do I connect to the db and extraxt information from the table?

Thank you
Old 05-25-2010, 06:00 AM   #2
LQ Newbie
Registered: Jul 2005
Distribution: Debian
Posts: 20

Rep: Reputation: 2
It depends:

1. Which scripts you prefer, Perl, Python or other?
2. What database you are working on, MySQL, SQLite or something else?

Export data from database table into csv is not necessary since many script languages provide database interfaces. For instance, the DBI for Perl.

Last edited by longbow0; 05-25-2010 at 06:03 AM.
Old 05-25-2010, 06:01 AM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,627

Rep: Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943
hmmm ... db ... Mysql, Oracle, DB2 ... and the list goes on

You will need to advise the database you are dealing with (I could assume mysql but long track if i am wrong) and you need to also tell us what you
would like to use, ie bash, perl, etc
Old 05-25-2010, 06:02 AM   #4
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
use this

sqlplus username/password@database_name << END
Your SQL Commands

sqlplus username/password@database_name @ abc.sql
where abc.sql contains your SQL commands

mysql -u username -p password database -e "Your SQL Commands"

Last edited by vikas027; 05-25-2010 at 06:02 AM. Reason: missed something


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to extract information element from Beacon Frame. Mr.J Linux - Wireless Networking 0 04-25-2009 10:49 PM
Extract Local User Information borisys Red Hat 1 02-20-2009 11:53 AM
How to extract information from a large data pool with AWK script? underskinned Programming 2 11-23-2006 10:26 PM
Bash: Extract Title Information From Playlist xxfunkxx Linux - Newbie 5 07-28-2004 03:31 AM
Extract information from mail boxes pcwulf Linux - Software 0 06-20-2004 09:04 PM > Forums > Linux Forums > Linux - Newbie

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

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