LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-29-2009, 09:01 PM   #1
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Rep: Reputation: 30
SQL to CSV; simple question?


I have an SQL database running on a remote host (I don't know how I would access files saved to that machine).

How do I save (or get) the query output to a CSV file?
 
Old 06-29-2009, 11:01 PM   #2
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 298

Rep: Reputation: 55
If the remote machine allows client connections you could login with (at least with mysql):
Code:
mysql --host=xxx.xxx.xxx.xxx --user=dbaselogin --password=mypassword
If you can't there is always the option of scp, ftp or http to transfer the resulting text file.

Try:
Code:
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
on the client computer.

Copied from http://www.tech-recipes.com/rx/1475/...t-or-csv-file/

Regards,
Stefan

Last edited by propofol; 06-29-2009 at 11:04 PM.
 
Old 07-01-2009, 04:45 PM   #3
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Original Poster
Rep: Reputation: 30
I couldn't write using the output command. If I had I don't know how I would have gotten the file.

Instead I just used redirects:
Code:
mysql --host=xxx.xxx.xxx.xxx --user=dbaselogin --password=mypassword < mysqlscript.sql > myoutputfile.csv
Thank you for your tips and suggestions.
 
  


Reply

Tags
csv, host, output, remote, sql


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
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 10:15 PM
SQL noob question: can SQL effectively handle a 2D matrix? JoeyAdams Programming 2 03-17-2008 02:10 AM
Simple SQL question joelhop Programming 1 10-06-2006 02:39 PM
help with simple sql statement sekelsenmat Programming 6 08-06-2005 01:01 PM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 10:03 PM


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

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