Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get table-formatted output from MySQL in non-interactive mode? [duplicate]

Tags:

mysql

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.

like image 332
dan Avatar asked Jan 14 '11 16:01

dan


2 Answers

Add the -t option to mysql (table).

  mysql -t -uroot mydb < myscript.sql

  mysql -t -uroot mydb -e 'select * from mytable'
like image 181
Déjà vu Avatar answered Sep 24 '22 13:09

Déjà vu


Use \P less -S option before running the query

mysql> \P less -S

PAGER set to 'less -S'

like image 35
Gaurav Phapale Avatar answered Sep 24 '22 13:09

Gaurav Phapale