I'm using PuTTY to run:
mysql> SELECT * FROM sometable;
sometable
has many fields and this results in many columns trying to be displayed in the terminal. The fields wrap onto the next line so it is very hard to line up column titles with field values.
What solutions are there for viewing such data in terminal?
I don't have nor want access to phpMyAdmin - or any other GUI interfaces. I'm looking for command-line solutions such as this one: Save MySQL Query results into text or CVS file
I wrote
pspg
- https://github.com/okbob/pspgThis pager is designed for tabular data - and MySQL is supported too.
Try enabling vertical mode, using
\G
to execute the query instead of;
:Your results will be listed in the vertical mode, so each column value will be printed on a separate line. The output will be narrower but obviously much longer.
I believe putty has a maximum number of columns you can specify for the window.
For Windows I personally use Windows PowerShell and set the screen buffer width reasonably high. The column width remains fixed and you can use a horizontal scroll bar to see the data. I had the same problem you're having now.
edit: For remote hosts that you have to SSH into you would use something like plink + Windows PowerShell
Using
mysql
'sego
commandFrom
mysql
'shelp
command:So by appending a
\G
to yourselect
, you can get a very clean vertical output:Using a pager
You can tell MySQL to use the
less
pager with its-S
option that chops wide lines and gives you an output that you can scroll with the arrow keys:Thus, next time you run a command with a wide output, MySQL will let you browse the output with the
less
pager:If you're done with the pager and want to go back to the regular output on
stdout
, use this:Using the Windows Command Prompt you can increase the buffer size of the window as much you want to see the number of columns. This depends on the no of columns in the table.
You can use the
--table
or-t
option, which will output a nice looking set of resultsor some other method to pass a query to mysql, like:
output: