MySQL - Output nice looking set of results from command line

By xngo on February 16, 2020

MySQL can returns nice looking set of results from your query. Simply use the --table or -t option. Here is an example. It describes the Indicator table from my htstbot database.

echo 'describe Indicator' | mysql -uroot htstbot -t
+-----------+---------------+------+-----+---------+-------+
| Field     | Type          | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| ticker_id | int(11)       | NO   | PRI | NULL    |       |
| date      | date          | NO   | PRI | NULL    |       |
| name      | varchar(100)  | NO   | PRI | NULL    |       |
| input     | varchar(100)  | NO   | PRI | NULL    |       |
| type      | tinyint(4)    | YES  |     | NULL    |       |
| value     | decimal(17,6) | NO   |     | NULL    |       |
| note      | varchar(255)  | YES  |     | NULL    |       |
+-----------+---------------+------+-----+---------+-------+

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.