How do you get table-formatted output from MySQL i

2020-08-22 07:06发布

I like the table output that the mysql client program produces in interactive mode, but if I try to run a sql script like this:

mysql -uroot mydb < myscript.sql

I only get tab-separated output.

mysql -uroot mydb -e 'select * from mytable'

does produce the output in the desired table format, however.

How can I get the first command to produce table-formatted output? I don't want HTML output, but the terminal character output with aligned columns and headers.

标签: mysql
2条回答
别忘想泡老子
2楼-- · 2020-08-22 07:45

Add the -t option to mysql (table).

  mysql -t -uroot mydb < myscript.sql

  mysql -t -uroot mydb -e 'select * from mytable'
查看更多
淡お忘
3楼-- · 2020-08-22 08:04

Use \P less -S option before running the query

mysql> \P less -S

PAGER set to 'less -S'

查看更多
登录 后发表回答