MySQL命令行具有特殊功能操作

写在前面

本文一起看下MySQL客户端命令行具有特殊功能的操作,比如换行,执行操作系统命令等。

1:结束并发送语句

使用;\G,我们一般使用前者较多。如:

mysql> select count(*) from db;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from db\G
*************************** 1. row ***************************
count(*): 2
1 row in set (0.00 sec)

2:执行系统命令

格式\! 系统命令,执行清空屏幕,如:

mysql> \! clear

查看目录下的文件,如:

mysql> \! ls /tmp
init.sql         systemd-private-22461c81c0f648caa81f92c591b68011-chronyd.service-3hjNRE  t.csv
mysql.sock       systemd-private-79bb2182444642aa8ce2539a5b765b72-chronyd.service-EmnTGg  t.sql
mysql.sock.lock  systemd-private-c758cf64149749c1a3f6d1047aef3e6b-chronyd.service-xfTbjA

3:退出客户端

\qexit,如:

mysql> \q
Bye
...
mysql> exit
Bye

4:清除sql但不执行

\c,如:

mysql> select count(*) from t\c
mysql> 

5:查看MySQL状态信息

\s,如:

mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.7.39, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:          7
Current database:       db1
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.7.39-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.sock
Uptime:                 2 hours 40 min 47 sec

Threads: 2  Questions: 148  Slow queries: 0  Opens: 163  Flush tables: 1  Open tables: 157  Queries per second avg: 0.015
--------------

6:帮助

\h

mysql> \h
...
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.
...

写在后面


版权声明:本文为wang0907原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。