Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate CSV based on MySQL query from phpMyAdmin

Can I generate a CSV file from phpMyAdmin based on a MySQL query?

For example, let's say I queried a table to return results for the word "image". Could I then produce a CSV with all of the records containing the word "image"?

like image 321
Jane Avatar asked Jun 04 '11 23:06

Jane


People also ask

How do I store the MySQL query results in a local csv file?

use the command insert...select to create a "result" table. The ideal scenario whould be to automatically create the fields of this result table, but this is not possible in mysql. create an ODBC connection to the database. use access or excel to extract the data and then save or process in the way you want.

How do I save a query in phpMyAdmin?

On the PHPMyAdmin SQL section, you will put your procedural query and save this query as a bookmark which you will see on the lower side of the page which I indicate with a red arrow. It's a good idea but you can also try to save your query on PHP function and run them using a function call.


2 Answers

In PhpMyAdmin, go into the SQL tab and enter your query in there. Hit go, then click Export at the bottom of your results. You can select to export as a CSV.

In case you're interested, here's how to do it via SQL without PMA: How to output MySQL query results in CSV format?

like image 175
SamT Avatar answered Oct 06 '22 00:10

SamT


You may be able to use the SELECT ... INTO OUTFILE... functionality. Although this will place the CSV file on the server. That's a long page, because it's the page for the whole "Select" syntax, but the basics are below:

SELECT col1,col2,col3 INTO OUTFILE '/tmp/result.txt'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM MyTable;
like image 40
Kibbee Avatar answered Oct 06 '22 00:10

Kibbee