Databases 8 min read

Unlock Hidden MySQL Client Commands: A Practical Guide

This article introduces many lesser‑known MySQL client shortcuts—such as \G, \R, \T and others—explaining their syntax, usage examples, and how they can streamline daily database operations for developers and administrators.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Unlock Hidden MySQL Client Commands: A Practical Guide

MySQL client commands contain many interesting and useful shortcuts that can greatly simplify routine tasks. While common shortcuts like \G, \c, \q, \P and \R are well known, this guide covers several lesser‑known commands.

If you are unsure about other MySQL client commands, use help or ? to list them.

1. help, ? – View Help Documentation

Use help or ? to display the full list of client commands.

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help`.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to MySQL server, display result vertically.
exit (\q) Exit MySQL. Same as quit.
go (\g) Send command to MySQL server.
help (\h) Display this help.
nopager (
) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your MySQL prompt.
quit (\q) Quit MySQL.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

2. Set CLI Prompt \R – prompt

Customize the MySQL prompt using the PROMPT command.

mysql> \R \u@\h [\d]>
PROMPT set to '\u@\h [\d]>'
msandbox@localhost [test]>

3. Edit Mode \e – edit

Launch your default editor (vi/vim) to edit a multi‑line SQL statement. After saving and exiting, terminate the command with a semicolon.

msandbox@localhost [(none)]> \e
use test;
select * from vvv limit 1;
-- after editing and saving (wq)
->;
Query OK, 0 rows affected (0.01 sec)
+------+------------+
| id   | name       |
+------+------------+
| 1    | sylar chen |
+------+------------+
1 row in set (0.01 sec)

4. Record Operation Log \T – tee

Redirect both the executed SQL statements and their output to a file, similar to the Linux tee command.

msandbox@localhost [test]> \T /tmp/sql.log
Logging to file '/tmp/sql.log'

5. Execute System Command \! – system

Run a shell command directly from the MySQL client.

msandbox@localhost [test]> \! cat /tmp/sql.log

6. Show Connection Status \s – status

Display detailed information about the current MySQL connection.

msandbox@localhost [test]> \s
--------------
/ usr/local/sandbox/boxes/5.5.36/bin/mysql 
Ver 14.14 Distrib 5.5.36, for linux2.6 (i686) using readline 5.1
Connection id: 22
Current database: test
Current user: msandbox@localhost
SSL: Not in use
Current pager: stdout
Using outfile: '/tmp/sql.log'
Using delimiter: ;
Server version: 5.5.36-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql_sandbox5536.sock
Uptime: 3 days 3 hours 9 min 44 sec
Threads: 1 Questions: 190 Slow queries: 0 Opens: 38
Flush tables: 1 Open tables: 31 Queries per second avg: 0.000
--------------

7. Pagination Display \P – pager

Use the Linux less or more utilities to page query results, or redirect them to a file.

\P less   # display output via less
\P more   # display output via more
\P cat /tmp/page.txt   # save output to /tmp/page.txt
\p or 
   # cancel pager output
Source: http://mdba.cn/2014/03/10/mysql-client%E4%B8%AD%E4%B8%80%E4%BA%9B%E8%A2%AB%E9%81%97%E5%BF%98%E7%9A%84%E5%8A%9F%E8%83%BD/
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIdatabasemysqlcommandsclient
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.