【MySQL技巧】定制你的MySQL命令行

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

我在登录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

 




本文转自gnuhpc博客园博客,原文链接:http://www.cnblogs.com/gnuhpc/archive/2012/12/21/2828294.html,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7月前
|
存储 缓存 关系型数据库
2.3 【MySQL】命令行和配置文件中启动选项的区别
2.3 【MySQL】命令行和配置文件中启动选项的区别
35 0
|
9月前
|
存储 关系型数据库 MySQL
MySQL下载与安装、mysql服务启动与停止、mysql使用cmd命令行登录、SQLyog下载与安装,sqlyog登录与操作mysql(一)
MySQL下载与安装、mysql服务启动与停止、mysql使用cmd命令行登录、SQLyog下载与安装,sqlyog登录与操作mysql
230 0
|
1月前
|
存储 关系型数据库 MySQL
|
8月前
|
关系型数据库 MySQL
MySQL 服务的启动与停止(通过命令行的方式)
MySQL 服务的启动与停止(通过命令行的方式)
71 0
|
9月前
|
关系型数据库 MySQL 测试技术
MySQL实战基础知识入门(1):登录数据库命令行
MySQL实战基础知识入门(1):登录数据库命令行
76 0
|
4月前
|
SQL 数据可视化 关系型数据库
【MySQL进阶之路丨第四篇】命令行与可视化工具
【MySQL进阶之路丨第四篇】命令行与可视化工具
76 0
|
5月前
|
XML SQL 关系型数据库
MySQL命令行格式化输出
MySQL命令行格式化输出
|
9月前
|
关系型数据库 MySQL
MySQL实战基础知识入门(5):命令行汉字中文输出乱码的解决方案
MySQL实战基础知识入门(5):命令行汉字中文输出乱码的解决方案
56 0
|
9月前
|
关系型数据库 MySQL 数据库
Phpstorm命令行查看MySql版本号
Phpstorm命令行查看MySql版本号
86 0
|
9月前
|
关系型数据库 MySQL 数据库
phpstudy集成环境设置环境变量命令行使用mysql
phpstudy集成环境设置环境变量命令行使用mysql
189 0