Forum Moderators: open

Message Too Old, No Replies

How to output query to text file in MySQL?

Using a direct connection how can I 'TEE' to a file

         

Demaestro

3:55 pm on Jul 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am using MySQL 5.0.27-standard

I SSH'd into the machine and started a MySQL session.

I want to output my queries to a text file. I opened help and it says to use -T to set a file and -t to unset it.

However I can't seem to get the syntax right. Can someone help me, I am not finding anything VIA search.

So I want my queries to output to /tmp/out.txt

I have tried

-T /tmp/out.txt;

-T '/tmp/out.txt';

-T /tmp/out.txt; select * from table;

Anyone know the magic phrase I need?
Please and thanks.

eelixduppy

5:11 pm on Jul 9, 2008 (gmt 0)



You make it as part of your query:

SELECT * FROM `table_name` INTO OUTFILE /path/to/file.txt

Refer to SELECT syntax for more information: [dev.mysql.com...]

Demaestro

7:27 pm on Jul 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



eelix... thank you!

as an FYI to anyone else.. I had to quote the file path.

So...

SELECT * FROM table INTO OUTFILE '/path/to/file.txt'