LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   mySQL redirecting query result to a .txt file! (https://www.linuxquestions.org/questions/linux-software-2/mysql-redirecting-query-result-to-a-txt-file-115266/)

buttersoft 11-12-2003 12:39 PM

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?

druuna 11-12-2003 01:28 PM

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

buttersoft 11-12-2003 01:41 PM

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

druuna 11-12-2003 01:54 PM

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.

buttersoft 11-12-2003 01:59 PM

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.

buttersoft 11-12-2003 03:17 PM

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......

artur 11-21-2003 10:45 AM

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

buttersoft 11-21-2003 12:42 PM

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

buttersoft 12-12-2003 03:05 AM





All times are GMT -5. The time now is 07:31 AM.