LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-12-2003, 01:39 PM   #1
buttersoft
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 178

Rep: Reputation: 30
mySQL redirecting query result to a .txt file!


select last, email from address where email <> "";

This brings back the results as expected BUT I want the results to be piped to a .txt file.

I tried select last, email from address where email <> "" > /home/diamond/test.txt;
select last, email from address where email <> "" | /home/diamond/test.txt;

both end with same result:-

ERROR 1064: You have an error in your SQL syntax near '/home/diamond/test.txt' at
line 1

What am I doing wrong?
 
Old 11-12-2003, 02:28 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
$ mysql < sql-batch > outfile

sql-batch holds your sql statements i.e:

use <dbname>
select * from sometable

Or from 'within' mysql (sqlprompt):

mysql> select * into outfile "/tmp/whatever" from some_table;
 
Old 11-12-2003, 02:41 PM   #3
buttersoft
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 178

Original Poster
Rep: Reputation: 30
Can't create/write to file '/home/diamond/test.txt' (Errcode: 13)

Now I have another error code.

I have specified my mysql password using -p
 
Old 11-12-2003, 02:54 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
You don't tell which option you tried.

Here's another option (for mysql prompt)

mysql> tee /tmp/whatever
mysql> <command>
mysql> <command>

All (!!) will be send to /tmp/whatever. You might need to clean up the output file.
 
Old 11-12-2003, 02:59 PM   #5
buttersoft
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 178

Original Poster
Rep: Reputation: 30
With each day we get nearer!

quote "The dead stay dead and the living only wait to join them........
with less hair"

Thank you tee /home/spb/testing.txt and then my sql query works perfect.

Bit different from Oracle that I was using..

Anyway Success at last.
 
Old 11-12-2003, 04:17 PM   #6
buttersoft
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 178

Original Poster
Rep: Reputation: 30
As I see from my new sql cookbook, page 30 Creating a tee file........introduced in MySQL 3.23.28, the Zaurus version is 3.22 that I have.

Does anyone know how to log interactive mysql sessions on a Zaurus to a text file like I have learnt to do on my desktop mavhine with tee /home/spb/testing.txt......
 
Old 11-21-2003, 11:45 AM   #7
artur
Member
 
Registered: Apr 2002
Location: Illinois, US
Distribution: Red Hat, Fedora, Yellow Dog, Debian, FreeBSD, Embedix
Posts: 106

Rep: Reputation: 15
Quote:
Originally posted by buttersoft
Does anyone know how to log interactive mysql sessions on a Zaurus to a text file like I have learnt to do on my desktop mavhine with tee /home/spb/testing.txt......
All your commands in mysql client are logged in ~/.mysql_history

My guess is that you were unable to select into outfile, because you were trying to write the outfile to a directory in which your MySQL server has no permission to write, e.g. your home directory. When you select into outfile, it is the server, not your client that writes the file. Whoever it runs as (daemon on my Z) has to be able to write to whereever you're trying to create your file. On my Z, when I entered just the file name, witout the path, outfile got created just fine in the /home/system/var/lib/mysql/mysql/ directory, which is probably not the best place to write files to...

Try writing to /tmp/outfile.txt The /tmp directory is supposed to be world-writable, although it is quite small on the Z
 
Old 11-21-2003, 01:42 PM   #8
buttersoft
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 178

Original Poster
Rep: Reputation: 30
Well I found out on the Z I can use copy and paste into a text file! That was all I needed the first time.......will investigate what you say about /tmp
 
Old 12-12-2003, 04:05 AM   #9
buttersoft
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 178

Original Poster
Rep: Reputation: 30



Last edited by buttersoft; 12-12-2003 at 04:09 AM.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
txt >> mysql LLS Programming 2 06-21-2005 12:15 PM
MySQL - Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 9 jasontn Linux - Software 0 02-09-2005 01:17 PM
MySQL queries from Shell - unexpected result philipz Programming 5 05-04-2004 06:38 PM
Mysql Error: Lost Connection to Mysql during query ramnath Programming 5 11-18-2003 01:27 PM
How to convert a txt file to be a db file in Redhat linux 9? winnie Linux - Newbie 3 06-27-2003 09:33 AM


All times are GMT -5. The time now is 09:30 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