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 wi开发者_如何学编程th all of the records containing the word "image"?
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?
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;
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.
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.
use adminer, adminer has option to export query results: https://www.adminer.org/
精彩评论