How to best display in Terminal a MySQL SELECT returning too many fields?

后端 未结 12 871
你的背包
你的背包 2020-12-04 04:32

I\'m using PuTTY to run:

mysql> SELECT * FROM sometable;

sometable has many fields and this results in many columns trying

12条回答
  •  醉梦人生
    2020-12-04 05:14

    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:

    [client]
    user=root
    password=MyPwD
    [mysql]
    pager='less -SFX'
    

    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:

    • -S: Single line, don't skip line when line is wider than screen, instead allow to scroll to the right.
    • -F: Quit if one screen, if content doesn't need scrolling then just send to stdout.
    • -X: No init, disables any output "less" might have configured to output every time it loads.

    Note: in the .my.cnf file don't put the pager command below the [client] keyword; although it might work with mysql well, mysqldump will complain about not recognizing it.

提交回复
热议问题