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
If you are using MySQL interactively, you can set your pager to use
sed
like this:If you don't use
sed
as the pager, the output is like this:This query displays the rows vertically, like this:
You might also find this useful (non-Windows only):
This will pipe the outut through the
less
command line tool which - with these parameters - will give you a tabular output that can be scrolled horizontally and vertically with the cursor keys.Leave this view by hitting the
q
key, which will quit theless
tool.Just to complement the answer that I thought best, I also use
less -SFX
but in a different way: I like to ad it to my.my.cnf
file in my home folder, an example cnf file looks like this:The good thing about having it this way, is that
less
is only used when the output of a query is actually more than one page long, here is the explanation of all the flags:Note: in the
.my.cnf
file don't put thepager
command below the[client]
keyword; although it might work withmysql
well,mysqldump
will complain about not recognizing it.The default pager is stdout. The stdout has the column limitation, so the output would be wrapped. You could set other tools as pager to format the output. There are two methods. One is to limit the column, the other is to processed it in vim.
The first method:
The output is not complete. The content fits to your screen.
The second one:
Set vim mode to nowrap in your .vimrc
You can use
tee
to write the result of your query to a file: