博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【MySQL技巧】定制你的MySQL命令行
阅读量:4619 次
发布时间:2019-06-09

本文共 1703 字,大约阅读时间需要 5 分钟。

作者:

出处:

我在登录MySQL后的命令行是这个样子的:

warmbupt@pchuang:/windows/MyCode/SS$ mysql -u root -ppassw0rd

Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 37
Server version: 5.1.37-1ubuntu5.1 (Ubuntu)
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql>

通过一系列改造,我们可以得到一个更加user-friendly的命令行提示符。

我们试着显示用户名、主机名和正在使用的数据库名称:

在shell命令行中设置环境变量:

export MYSQL_PS1="/u@/h [/d]> " 其中
  • /u – Username 用户名
  • /h – Hostname 主机名
  • /d – Current mysql database 当前数据库

当然,你可以将该命令写入bashrc以后在bash下使用都能得到这样的命令行提示符了。或者你可以在MySQL的配置文件/etc/my.cnf 或.my.cnf设置:

prompt=//u@//h [//d]>//_

另外,你在MySQL内也可以设置:

prompt /u@/h [/d]> 在你想回归原始的时候你可以在MySQL中键入prompt即可回归(回到在MySQL外部的设置,若你在bashrc中写入的话即回归到bashrc中的设置状态)。
附变量表:

Generic variables:

  • /S displays semicolon
  • /’ displays single quote
  • /” displays double quote
  • /v displays server version
  • /p displays port
  • // displays backslash
  • /n displays newline
  • /t displays tab
  • / displays space (there is a space after / )
  • /d displays default database
  • /h displays default host
  • /_ displays space (there is a underscore after / )
  • /c displays a mysql statement counter. keeps increasing as you type commands.
  • /u displays username
  • /U displays username@hostname accountname

Date related variables:

  • /D displays full current date (as shown in the above example)
  • /w displays 3 letter day of the week (e.g. Mon)
  • /y displays the two digit year
  • /Y displays the four digit year
  • /o displays month in number
  • /O displays 3 letter month (e.g. Jan)
  • /R displays current time in 24 HR format
  • /r displays current time in 12 hour format
  • /m displays the minutes
  • /s displays the seconds
  • /P displays AM or PM

 

作者:

出处:

转载于:https://www.cnblogs.com/gnuhpc/archive/2012/12/21/2828294.html

你可能感兴趣的文章
局部变量和static变量的区别
查看>>
IE下iframe不能正常加载,显示空白
查看>>
mysql服务性能优化—my.cnf配置说明详解
查看>>
洛谷P1908 逆序对
查看>>
noip模拟赛 排列
查看>>
List 中添加多个List集合以及add() 与addAll()的区别
查看>>
如何处理测试人员的流动问题?
查看>>
1.border-image
查看>>
PagerIndicator主题样式修改
查看>>
java中HashMap类用法
查看>>
完整部署CentOS7.2+OpenStack+kvm 云平台环境(2)--云硬盘等后续配置
查看>>
分布式监控系统Zabbix-完整安装记录 -添加端口监控
查看>>
Python之反向迭代
查看>>
STM32F4 输入输出(GPIO)模式理解
查看>>
转义符
查看>>
poj 1019
查看>>
asp.net mvc上传文件
查看>>
bitmq集群高可用测试
查看>>
subline text3利用正则搜索
查看>>
项目管理思考——职责
查看>>