DBA 101: Sometimes forgotten functionality in the MySQL client

The MySQL client has some functionalities some of us never use. Why would you use them and what is the added value of this?

Every DBA and developer has had a moment when he or she needs to connect to a MySQL database using the command line tool. Therefore I’ve written down an explanation of some command line commands you can insert in the CLI, most of them give added value and make your experience with the cli more enjoyable.


Who has never witnessed the scary feeling of not being connected to the write database when having several terminals open. I do, due to the fact I use the prompt functionality.

Or you can go a bit further and visualise the user, host and active database in:


In some situations editing the query in an editor instead of the cli can have several enhancements. It gives you the ability to fix typos, have a deep look at the queries before you submit them and etc.
If you’d like to edit the query you are making in your default editor instead of using the cli.

The editor appears, in which you can create your query/ies.

After closing this down and putting a delimiter in the cli, this query will be run against the database while outputting in the prompt.


Performing critical maintenance on a database could require to have an entire log of performed queries and actions. You can activate the full output of the MySQL client, including your performed queries. This utility is ideal if you prefer having a log of all of your actions. This could be for documentation stakes or a way to reread your actions if issues would occur.


This will provide in the output the queries you perform.

Whenever, you have only access to the MySQL interface and you need to access one of your created files to see what the output is, you can do so using the ! keystroke, which will execute system commands.
Running a shell command from the MySQL command line interface:


In some cases you’d like seeing the parameters currently active on your MySQL client. Therefore you can actually use the s command. This command will clarify which of the options are active on the client. The info which is shown should not be confused with SHOW VARIABLES. which is focussed on the connection variables.
Trigger the status information of your connection using s:


Clearing your current input query. Use c to clear the input field:


Honestly one of the more useful tools in the mysqlclient is actually pager. For people prone to typing queries while forgetting adding a limit if they don’t need to view the full output.
‘P less’ will output the query data using the UNIX command less.
You can also choose to output the query results in a parsable format on the filesystem using ‘P cat > voila.log’.

for example:

This will create the file ‘voila.log’ in which only the output is saved of the query. This solution mimics the ‘SELECT INTO OUTFILE’ query.

During optimisation of your workload, it can be interesting to see if a query you’ve modified has the same query output

Other commands

There are of course several other options you might use. You can get an overview of all the internal cli functions through ?.

Disabling the tee and pager commands described in this blogentry can be done with t or notee, n or nopager.

Share this post

Comments (10)

  • Mark Willis

    using the md5sum is a great idea. This will definitely help with query optimisation.


    February 27, 2014 at 6:12 am
  • Joshua Prunier

    Pager is extremely useful! I often use it with grep to quickly filter just the contents I want.

    mysql> pager grep Log
    PAGER set to ‘grep Log’
    mysql> show engine innodb status\G
    Log sequence number 39598733324687
    Log flushed up to 39598733324677
    1 row in set (0.00 sec)

    Great post, thank you for sharing.

    February 27, 2014 at 8:48 am
  • Jaime Crespo

    Sounds familiar, Dimitri 🙂 You should also fix your default charset connection, or the citizens of the great city of “A Coruña” may complain!

    February 27, 2014 at 11:20 am
  • Kris

    I really like the prompt, never seen that. Can this be passed in when the cli is started?

    February 27, 2014 at 8:50 pm
  • Kris

    To answer my own question yes you can with a –prompt=’\u@\h [\d]>’

    February 27, 2014 at 8:56 pm
  • eik3


    (delete this comment)

    February 28, 2014 at 6:07 am
  • Andrew Moore

    Today using some pager + egrep to find long running TRX

    pager egrep ‘ACTIVE [0-9].’

    February 28, 2014 at 10:34 am
  • sshaw

    I always set my pager to: less -F which will only page the results when the output wont fit in the terminal.

    Also from within less one can search using regexs via less’ / or ? commands -in addition to other fun stuff (less is quite a powerful pager).

    On OS X you need to do: TERM=vt100 less -F

    February 28, 2014 at 10:15 pm
  • Shantanu Oak

    I create an alias so that I do not need to remember the syntax.

    alias mysql_new=’mysql –prompt=”(\r:\m)\_mysql@\h>” –show-warnings –tee=”/tmp/sqltee.txt”‘

    I use prompt, tee, pager and status. But edit command is new to me. And “pager less -F” trick mentioned in the comments is really useful.

    March 2, 2014 at 11:38 pm
  • Pardeep Koundal

    Great blog for Knowledge

    May 13, 2019 at 10:17 am

Comments are closed.

Use Percona's Technical Forum to ask any follow-up questions on this blog topic.