So you’re hammering away at the console and shoot a couple of queries at mysql only to realise that the result you were after has flown by and out of sight! Luckily I can think of two ways to fix this.

Method 1:

Execute single SQL queries from your shell like so:

1
mysql -u root -proot -e "show tables;" some_database | more
  • u – username
  • p – password (note that there is NO space between the ‘p’ and your password)
  • e – the SQL query to execute
  • some_database – the database to use
  • | more – pipe the output to the *nix pager more

Method 2:

At your mysql prompt define the pager that you’d like to use and then execute your query as usual:

1
2
3
mysql> pager more;
mysql> use some_database;
mysql> show tables;

Sorted :D