将 Mysql 查询的结果导出到 excel?

Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)
本文介绍了将 Mysql 查询的结果导出到 excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的需求是存储查询的全部结果

My requirement is to store the entire results of the query

SELECT * FROM document 
WHERE documentid IN (SELECT * FROM TaskResult WHERE taskResult = 2429)

到一个 Excel 文件.

to an Excel file.

推荐答案

实现此目的的典型方法是导出为 CSV,然后将 CSV 加载到 Excel 中.
您可以使用任何 MySQL 命令行工具来执行此操作,方法是在 SELECT 语句中包含 INTO OUTFILE 子句:

The typical way to achieve this is to export to CSV and then load the CSV into Excel.
You can using any MySQL command line tool to do this by including the INTO OUTFILE clause on your SELECT statement:

SELECT ... FROM ... WHERE ... 
INTO OUTFILE 'file.csv'
FIELDS TERMINATED BY ','

有关详细选项,请参阅此链接.

See this link for detailed options.

或者,您可以使用 mysqldump 使用 --tab 选项将转储存储为分隔值格式,请参阅 此链接.

Alternatively, you can use mysqldump to store dump into a separated value format using the --tab option, see this link.

mysqldump -u<user> -p<password> -h<host> --where=jtaskResult=2429 --tab=<file.csv> <database> TaskResult

提示:如果您没有指定绝对路径而是使用诸如 INTO OUTFILE 'output.csv'INTO OUTFILE './output.csv' 之类的内容,它将输出文件存储到由 show variables like 'datadir'; 指定的目录.

Hint: If you don't specify an absoulte path but use something like INTO OUTFILE 'output.csv' or INTO OUTFILE './output.csv', it will store the output file to the directory specified by show variables like 'datadir';.

这篇关于将 Mysql 查询的结果导出到 excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)