Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Linux command line tool and properly formatted results [duplicate]

Tags:

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 the results are 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 know I could use phpMyAdmin or the MySQLCC but I'm looking for a command-line solution.

like image 634
Peter Bushnell Avatar asked Oct 08 '13 10:10

Peter Bushnell


People also ask

How do I get MySQL output?

The Output is located at the bottom of MySQL Workbench. Its select box includes the Action Output , History Output , and Text Output options.

Which command is used in MySQL command line tool to return to Window command shell?

The EXIT or QUIT commands take you returned to windows from MySQL command line tool.

Which MySQL command shows the structure of a table?

To show the schema, we can use the DESC command. This gives the description about the table structure.

What is G in MySQL?

A little publicized, but exceedingly useful feature of the MySQL command line client is the \G modifier. It formats the query output nicely, so you can read through it easier. To use it, you just replace the semi-colon at the end of the query with '\G'.


1 Answers

You can obtain a vertically formatted output with \G.

This is the standard output:

mysql> select * from tblSettings; +-----------+----------------+---------------------+ | settingid | settingname    | settingvalue        | +-----------+----------------+---------------------+ |         1 | maxttl         | 30                  | |         2 | traceroutepath | /usr/bin/traceroute | |         3 | alertemail     | [email protected]         | +-----------+----------------+---------------------+ 3 rows in set (0.00 sec) 

And this is what the output looks like with \G:

mysql> select * from tblSettings \G; *************************** 1. row ***************************    settingid: 1  settingname: maxttl settingvalue: 30 *************************** 2. row ***************************    settingid: 2  settingname: traceroutepath settingvalue: /usr/bin/traceroute *************************** 3. row ***************************    settingid: 3  settingname: alertemail settingvalue: [email protected] 3 rows in set (0.00 sec) 
like image 57
jwbensley Avatar answered Sep 30 '22 19:09

jwbensley