MySQL Client 小技巧
文章
林里克斯
mysql client
命令的一些小技巧
1、help,?
mysql> help
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 (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the 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. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
2、设置 CLI
提示 \R
mysql> \R \u@\h [\d]>
PROMPT set to '\u@\h [\d]>'
root@127.0.0.1 [(none)]>use blog;
Database changed
root@127.0.0.1 [blog]>
3、编辑模式 \e
进入 vi/vim
中编辑 sql
,编辑完成之后保存,回到 mysql CLI
中,输入 “;”
后按 enter
键即可执行刚才编辑的 sql
语句
root@127.0.0.1 [blog]>\e
use mysql;
show tables;
(wq vim保存代码)
-> ;
root@127.0.0.1 [blog]>\e
-> ;
Query OK, 0 rows affected (0.00 sec)
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| db |
| user |
+---------------------------+
2 rows in set (0.00 sec)
4、记录操作日志 \T
,tee
差不多就是 linux tee
命令的功能,把执行的 sql
语句以及输出结果保存到指定的文件中。\t
,取消把查询和输出结果记录到文件中。
root@127.0.0.1 [blog]>\T /tmp/sql.log
Logging to file '/tmp/sql.log'
root@127.0.0.1 [blog]>use mysql;
Database changed
root@127.0.0.1 [mysql]>show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| db |
| user |
+---------------------------+
2 rows in set (0.00 sec)
$ cat /tmp/sql.log
root@127.0.0.1 [blog]>use mysql;
Database changed
root@127.0.0.1 [mysql]>show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| db |
| user |
+---------------------------+
2 rows in set (0.00 sec)
5、执行系统命令!
root@127.0.0.1 [mysql]>\! cat /tmp/netcount.txt
eth0
eth1
lo
lo
6、查看当前连接的状态信息 \s
root@127.0.0.1 [mysql]>\s
--------------
mysql Ver 14.14 Distrib 5.6.39, for Linux (x86_64) using EditLine wrapper
Connection id: 751
Current database: mysql
Current user: root@172.22.0.1
SSL: Not in use
Current pager: stdout
Using outfile: '/tmp/sql.log'
Using delimiter: ;
Server version: 5.7.22 MySQL Community Server (GPL)
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 6 hours 39 min 27 sec
Threads: 1 Questions: 30425 Slow queries: 0 Opens: 379 Flush tables: 1 Open tables: 372 Queries per second avg: 1.269
--------------
Over~
版权协议须知!
本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
1182 0 2020-09-19
博主卡片
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。
现在时间 2024-12-27
今日天气
随机推荐
08-17
zabbix 监控 Windows
08-16
zabbix 监控 树莓派4B CPU 温度
02-10
Tomcat调优及启动脚本
05-21
常见的Linux系统简单面试题(二)
站点统计
- 文章总数:241篇
- 分类总数:29个
- 评论总数:12条
- 本站总访问量 352761 次
@xiaozi 最后的分享的镜像下载地址打不开 服务器没有开机吗?
@yuanyuan 为什么我的4b安装centos7.9 插上tf卡 显示不兼...
@Wong arrhenius 牛比
@MakerFace 厉害了!
@TongSir 老哥 更新下我的友链链接 https://blog.ton...