tghw
tghw

Reputation: 25303

MySQL Results to a File

How do I write the results from a mysql query to file? I just need something quick. Output can be CSV, XML, HTML, etc.

Upvotes: 12

Views: 8222

Answers (3)

Farinha
Farinha

Reputation: 18091

You can use MySQL Query Browser to run the query and then just go to File -> Export Resultset and choose the output format. The options are CSV, HTML, XML, Excel and PLIST.

Upvotes: 1

Daren Thomas
Daren Thomas

Reputation: 70314

if you have phpMyAdmin installed, it is a nobrainer: Run the query (haven't got a copy loaded, so I can't tell you the details, but it really is easy) and check neer bottom for export options. CSV will be listed, but I think you can also have SQL if you like :)

phpMyAdmin will give CSV in Excels dialect, which is probably what you want...

Upvotes: 1

Matt Rogish
Matt Rogish

Reputation: 24873

SELECT a,b,a+b 
  FROM test_table
  INTO OUTFILE '/tmp/result.txt'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'

(the docs show INTO OUTFILE up in the SELECT .. portion which may work as well, but I've never tried it that way) http://dev.mysql.com/doc/refman/5.0/en/select.html

INTO OUTFILE creates a file on the server; if you are on a client and want it there, do:

mysql -u you -p -e "SELECT ..." >  file_name 

Upvotes: 20

Related Questions