作者: | 来源:互联网 | 2023-06-23 16:08
Ioftenworkincommandlinemysql.Acommonneedistotakeaquerysresultsandimporttheminto
I often work in command line mysql. A common need is to take a query's results and import them into a Numbers document (similar to an Excel document).
我经常在命令行mysql中工作。一个常见的需求是获取查询的结果并将其导入数字文档(类似于Excel文档)。
What is the fastest method for doing this?
最快的方法是什么?
Method 1: Select into outfile
You can select into an outfile directly from MySQL, but this takes several steps.
您可以直接从MySQL选择输出文件,但这需要几个步骤。
- export your query with all the necessary arguments to make it a CSV format, like
FIELDS OPTIONALY ENCLOSED BY
and DELIMITED BY
.
- 导出包含所有必要参数的查询,使其成为CSV格式,如由和分隔的字段OPTIONALY。
- sftp into the server and grab the file
- sftp进入服务器并抓取文件
- delete the file from the server
- 从服务器删除文件
Method 2: Copy/paste
I tend to do this method. For me it seems a little faster but that's mostly because I don't remember how to construct the SELECT INTO OUTFILE
query from above and have to look it up.
我倾向于用这种方法。对我来说,它似乎有点快,但这主要是因为我不记得如何从上面构造SELECT INTO OUTFILE查询,并且必须查找它。
- Copy/paste to a local text file
- 复制/粘贴到本地文本文件
- Open in a text editor and replace | with ,
- 在文本编辑器中打开并将|替换为,
- Save as a CSV and open in Numbers.
- 保存为CSV并打开数字。
6 个解决方案