根据来自 phpMyAdmin 的 MySQL 查询生成 CSV
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6239956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate CSV based on MySQL query from phpMyAdmin
提问by Jane
Can I generate a CSV file from phpMyAdmin based on a MySQL query?
我可以根据 MySQL 查询从 phpMyAdmin 生成 CSV 文件吗?
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"?
例如,假设我查询了一个表以返回“图像”一词的结果。然后我可以生成一个包含“图像”一词的所有记录的 CSV 文件吗?
回答by SamT
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.
在 PhpMyAdmin 中,进入 SQL 选项卡并在其中输入您的查询。点击开始,然后点击Export
结果底部的。您可以选择导出为 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?
如果您有兴趣,这里是如何在没有 PMA 的情况下通过 SQL 执行此操作:如何以 CSV 格式输出 MySQL 查询结果?
回答by Kibbee
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 ... INTO OUTFILE...功能。虽然这会将 CSV 文件放在服务器上。这是一个很长的页面,因为它是整个“选择”语法的页面,但基础知识如下:
SELECT col1,col2,col3 INTO OUTFILE '/tmp/result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM MyTable;
回答by Elango Paul Victor
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.
它创建了一个表,然后我将表导出为 CSV。这个解决方案对我来说很好。
回答by Beatroot
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
同样有效的是使用查询创建一个表,然后像往常一样导出该表,使 phpmyadmin 导出的所有选项都可用。只需在phpmyadmin的SQL框中做这样的事情
create table tmp_export
select * from xxxx
No problems with complex queries and large datasets using this approach.
使用这种方法处理复杂查询和大型数据集没有问题。