How to export / dump a MySql table into a text file including the field names (aka headers or column names)

后端 未结 6 932
盖世英雄少女心
盖世英雄少女心 2020-11-29 05:05

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

There seems to be no simple way to export a table to a tab-delimt

6条回答
  •  Happy的楠姐
    2020-11-29 05:36

    I achieved that in this way:

    echo "select * from table"| mysql database -B -udbuser -puser_passwd | sed s/\\t/,/g > query_output.csv
    

    The -B option of mysql separates the columns by tabs, which are converted into commas using sed. Note that the headers are generated too.

提交回复
热议问题