How can I add headers and format MySQL query output files?

折月煮酒 提交于 2019-12-12 02:44:56

问题


I connect to mysql from my Linux shell and use something like this:

SELECT * FROM students INTO OUTFILE '/tmp/students'.
  1. Why do I see \N at line endings? I want each record in a row, but why do I see the \N explicitly printed?

  2. How can I print all column headers in the first row?


回答1:


SELECT ... INTO OUTFILE exports the result to a rather mysql specific delimited format. \N means a NULL value, not end-of-line.

Run e.g. from a command line:

echo 'select * from students' | mysql mydb >/tmp/students

The documentation for SELECT shows you how what options you have when using INTO OUTFILE, but you can't export the headers directly that way. See the comments in that documentation for a hacky way of adding header columns though.



来源:https://stackoverflow.com/questions/3787737/how-can-i-add-headers-and-format-mysql-query-output-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!