Reputation: 987
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"?
Upvotes: 54
Views: 69826
Reputation: 336
use adminer, adminer has option to export query results: https://www.adminer.org/
Upvotes: -1
Reputation: 141
create table tmp_export
SELECT * from table_name WHERE column_name .....
It created a table and then I exported the table as CSV. This solution worked fine for me.
Upvotes: 14
Reputation: 476
What also works well is creating a table with the query and then export the table as usual, having all the options of phpmyadmin export available. Simply do something like this in SQL box of phpmyadmin
create table tmp_export
select * from xxxx
No problems with complex queries and large datasets using this approach.
Upvotes: 3
Reputation: 10620
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?
Upvotes: 84
Reputation: 66132
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;
Upvotes: 22