Generate CSV based on MySQL query from phpMyAdmin

痞子三分冷 提交于 2020-06-24 11:05:13

问题


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"?


回答1:


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?




回答2:


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;



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/6239956/generate-csv-based-on-mysql-query-from-phpmyadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!