如何将MySql表导出/转储到文本文件中,包括字段名称(也称为标题或列名称) [英] How to export / dump a MySql table into a text file including the field names (aka headers or column names)

查看:858
本文介绍了如何将MySql表导出/转储到文本文件中,包括字段名称(也称为标题或列名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySql的解释器中,将表格及其字段名称一起转储到屏幕是非常容易的。

In MySql's interpreter, it's very easy to dump a table to the screen along with its field names.

似乎没有简单的方法将表导出到制表符分隔符或CSV文件,包括其列标题。

There seems to be no simple way to export a table to a tab-delimted or CSV outfile including its column headers.

我只想使用SQL或Linux命令行,而不用另一种语言编写程序。

I'm trying to do this using only SQL or the Linux command line, without writing a program in another language.

谢谢

推荐答案

将查询配置到命令行客户端输出具有列名称的标签分隔列表作为第一行

Piping the query to the commandline client outputs a tab separated list with the column names as the first line

$ echo "select * from surveys limit 5" | mysql -uroot -pGandalf surveys
phone   param1  param2  param3  param4  p0      p1      p2      p3      audio4  code    time
XXXXXXXXX       2008-07-02      11:17:23        XXXXXXXX        SAT     -       -       -       -       -       ERROR   2008-07-02 12:18:32
XXXXXXXXX       2008-07-02      11:22:52        XXXXXXXX        SAT     -       -       -       -       -       COLGADO 2008-07-02 12:04:29
XXXXXXXXX       2008-07-02      11:41:29        XXXXXXXX        SAT     -       -       -       -       -       COLGADO 2008-07-02 12:07:22
XXXXXXXXX       2008-07-02      12:16:19        XXXXXXXX        SAT     1       1       1       9       XXXXXXXXX_4.wav     OK      2008-07-02 16:14:27
XXXXXXXXX       2008-07-02      08:21:25        XXXXXXXX        SAT     1       1       1       1       XXXXXXXXX_4.wav     OK      2008-07-02 12:29:40

这篇关于如何将MySql表导出/转储到文本文件中,包括字段名称(也称为标题或列名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆