经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » MySQL » 查看文章
mysql prompt用法详解
来源:cnblogs  作者:小有志气  时间:2021/4/6 9:43:16  对本文有异议

  当我们用mysql client连接mysql实例的时候我们想要显示我们连接的是那个实例、用哪个账号登录的、现在在哪个database中、现在系统时间等等很多信息的时候,那么mysql prompt将需要配置,以下将介绍prompt的配置详解,以及配置方法:

1、我们可以放在默认配置文件的mysql项目中,当我们登录的时候我们就可以看到如期显示了我们配置的信息:

  1. root@DESKTOP-1T4MD6P:~# more /etc/my.cnf
  2. [mysql]
  3. prompt="\\u@\\h [\\d]>"
  4. root@DESKTOP-1T4MD6P:~# mysql -S /tmp/mysql3306.sock
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 25
  7. Server version: 8.0.23 MySQL Community Server - GPL
  8. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  13. root@localhost [(none)]>

2、如果我们的配置文件不是默认配置文件,那么我们登录的时候需要指定配置文件也可以:

  1. root@DESKTOP-1T4MD6P:~# mysql --defaults-file=/etc/myback.cnf -S /tmp/mysql3306.sockWelcome to the MySQL monitor. Commands end with ; or \g.
  2. Your MySQL connection id is 26
  3. Server version: 8.0.23 MySQL Community Server - GPL
  4. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  5. Oracle is a registered trademark of Oracle Corporation and/or its
  6. affiliates. Other names may be trademarks of their respective
  7. owners.
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9. root@localhost [(none)]>

3、如果我们只是临时用一下不想创建或者修改配置文件,那么我们可以在登录的时候直接指定参数:

  1. root@DESKTOP-1T4MD6P:~# mysql -S /tmp/mysql3306.sock --prompt="\\u@\\h [\\d]>"

接下来我们整理一下可以定制哪些信息以及哪个字符对应什么信息:

\C 当前连接的标志符,也就是说从show processlist中看到当前连接的ID
\c 每次新连接执行语句计数器
\D 当前完整时间,包括年月日时分秒
\d 当前数据库,比如user test则显示test,如果没有执行use命令则显示(none)
\h 实例连接地址
\l ";"分界符,可以用于多个配置之间
\m 当前时间分钟
\n 换行符
\O 三个字母的月份
\o 数字格式的月份
\P 上午下午
\p 当前TCP/IP端口
\R 当前时间小时,24时制
\r 当前时间小时,12时制
\S 分号
\s 当前时间秒
\t 制表符
\U 完整账户名称user_name@host_name
\u 用户名user_name
\v MySQL服务器版本
\w 当前周几
\Y 当前4位数字年
\y 当前2位数字年
\_ 空格
\  
\' 单引号
\" 双引号
\\  
\x  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

其实我们日常用的比较多的可能就是用户名、连接地址、数据库名、时间等参数,可以根据需求定制;

原文链接:http://www.cnblogs.com/xiaoyouzhiqi/p/14611958.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号