8

I am using MySQL Ver 14.14 Distrib 5.5.44 for debian-linux-gnu.

How can I show my tables page wise in a terminal?

2 Answers 2

8

You can use the pager (see docs) command in MySQL console or use the --pager startup option (docs again) to redirect the output of your commands to an external executable.

To use the pager command and list the tables try this:

mysql> pager less
mysql> show tables

You can also start MySQL to send all your output to an external executable like this

mysql --pager=/usr/bin/less
1
  • For completeness' sake, this can also be set in ~/.my.cnf in the [client] section: pager = /usr/bin/less.
    – ckujau
    May 17, 2019 at 20:09
5

You might also find the tee command to be of use.

Log all output to an operating system file mytabs.txt.

mysql> tee mytabs.txt;
Logging to file 'mytabs.txt'

Issue your show tables command as below.

mysql> show tables;
+-----------------+
| Tables_in_sport |
+-----------------+
| billy           |
| player          |
| seasons         |
| team            |
+-----------------+
4 rows in set (0.00 sec)

Examine the contents of your file from within the mysql client. \! is the handy command for that.

mysql> \! more mytabs.txt;
mysql> show tables;        <<----- file contents
+-----------------+
| Tables_in_sport |
+-----------------+
| billy           |
| player          |
| seasons         |
| team            |
+-----------------+
4 rows in set (0.00 sec)

Turn of output logging.

mysql> notee;
Outfile disabled.

You can also examine the contents of the file via the shell - or alternatively, you could have your mysql client open and a shell terminal and switch between the two. Useful if you want permanent output to which you can refer later.

mysql> exit;
Bye
[pol@localhost inst]$ more mytabs.txt 
mysql> show tables;
+-----------------+
| Tables_in_sport |
+-----------------+
| billy           |
| player          |
| seasons         |
| team            |
+-----------------+
4 rows in set (0.00 sec)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.