Peter Bushnell Peter Bushnell - 3 months ago 7
MySQL Question

Mysql linux command line tool for properly formatted results

Does anyone know of a good tool to use from the shell to query the database and get intelligible results?

On the command line from SSH I want to query the database using mysql but find the results pretty much unreadable because there is no formatting for the terminal screen.

If I run the following it is vary hard to make sense of the results.

use mydb;
select * from db3_settings;


I can use phpMyAdmin or the MySQLCC but want to have something for the cmd line.

Answer

You can format the output with \G;

This is the standard output;

mysql> select * from tblSettings;
+-----------+----------------+---------------------+
| settingid | settingname    | settingvalue        |
+-----------+----------------+---------------------+
|         1 | maxttl         | 30                  |
|         2 | graphhopscale  | 1                   |
|         3 | tracedelta     | 2                   |
|         4 | traceroutepath | /usr/bin/traceroute |
|         5 | tracealert     | Yes                 |
|         6 | maxbars        | 50                  |
|         7 | alertemail     | me@host.com         |
+-----------+----------------+---------------------+
7 rows in set (0.00 sec)

This is the formatted output;

mysql> select * from tblSettings \G;
*************************** 1. row ***************************
   settingid: 1
 settingname: maxttl
settingvalue: 30
*************************** 2. row ***************************
   settingid: 2
 settingname: graphhopscale
settingvalue: 1
*************************** 3. row ***************************
   settingid: 3
 settingname: tracedelta
settingvalue: 2
*************************** 4. row ***************************
   settingid: 4
 settingname: traceroutepath
settingvalue: /usr/bin/traceroute
*************************** 5. row ***************************
   settingid: 5
 settingname: tracealert
settingvalue: Yes
*************************** 6. row ***************************
   settingid: 6
 settingname: maxbars
settingvalue: 50
*************************** 7. row ***************************
   settingid: 7
 settingname: alertemail
settingvalue: me@host.com
7 rows in set (0.00 sec)
Comments