mysql 客户端命令( \ 命令)

这篇博客详细介绍了MySQL客户端的各种命令,包括帮助、连接、分隔符设置、编辑、执行、退出、显示结果、设置提示符、重置连接等。此外,还提到了如何查看和管理查询历史,以及如何通过source命令执行SQL脚本。内容涵盖了MySQL客户端的基本操作,对于日常数据库管理和开发非常实用。
摘要由CSDN通过智能技术生成

mysql 客户端命令:
常用的 \ 命令

mysql> help

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

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.
resetconnection(\x) Clean session context.

For server side help, type 'help contents'

clear, \c  清除当前输入,在sql 键入一半时 可以直接 \c 取消.
mysql> select * from  \c

 connect, \r 重新连接到服务器。
mysql> \r

delimiter, \d  更改mysql解释为 SQL 语句之间分隔符的字符串。默认值为分号字符 ( ;)

当前会话生效。
mysql> \d /
mysql> show processlist/

 edit, \e 编辑当前输入语句.
show processlist; \e 当前语句用vi 编辑打开,编辑。

ego , \G 将当前语句发送到服务器执行,并以垂直格式显示结果.
mysql> show processlist \G


exit, \q 退出mysql
quit, \q 退出mysql

go , \g 将当前语句发送到要执行的服务器。
mysql> show processlist \g


nopager , \n 禁用输出分页。
pager , \P    启用输出分页

notee , \t 禁用输出复制到 tee 文件。

mysql> tee mytest    --tee 文件名; mysql 的sql执行打印输出到文件。
Logging to file 'mytest'
mysql> \t 禁用,停止tee输出。

tee , \T   记录语句及其输出。

print , \p   打印当前输入语句而不执行它。

prompt , \R  将mysql提示符重新配置为给定的字符串。
mysql> \R ml  --mysql 提示符修改为ml

ml\R      --改回默认提示符

 


rehash , \#   输入语句时重建完成哈希,以启用数据库、表和列名称完成。


source , \. filename  读取命名文件并执行其中包含的语句.

status , \s   提供有关连接和您正在使用的服务器的状态信息.

 

system , \!  执行shell 命令
mysql> \! ls
anaconda-ks.cfg  cretest2.sql     DBD-Oracle-1.74.tar.gz          mongoshake.tar.gz                           percona-toolkit-3.0.3                redis-6.0.1
mysql>

use , \u db_name 使用db_name作为默认数据库。
mysql> \u test

warnings , \W 在每个语句之后启用警告显示(如果有的话)。
nowarning , \w  禁止在每个语句后显示警告。


resetconnection, \x  重置连接以清除会话状态.
重置连接的效果类似于 mysql_change_user()或 自动重新连接,但连接不会关闭和重新打开,并且不会进行重新身份验证。
注意说明:这个.mysql_history不是只存在于MySQL所在的Server, 任何你能够远程用mysql连接,都会在此server上的当前用户的~目录下创建这个隐藏文件。(在你连接端的目录下记录的)
此文件可以通过配置用户的环境变量值修改:

export MYSQL_HISTFILE=/root/.mydb_history

mysql 客户端历史记录,存于文件.mysql_history中,文件一般在管理用户的家目录下,root用户在 /root 下,mysql 在/home/mysql目录下。
使用
sed "s/\\\040/ /g" < .mysql_history   可以替换文件中的 \040 为空格输出,提高可读性。

为安全可以设置此文件默认路径,做一些软连接,定期清除。
 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值