--prompt=name 参数对于做运维的人来说很重要。我们登入mysql数据库后,mysql的提示符只是一个很简单内容 mysql> ,没有其他任何信息。通过--prompt=name可以自定义提示信息,通过配置显示登入的主机地址,登陆用户名,当前时间,当前数据库schema等待。

[root@zw-test-db ~]# mysql -uroot -p --prompt="\\u@\\h : \\d\\r:\\m:\\s>"

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 33

Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost : (none) 05:45:21>use test

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

root@localhost : test 05:45:56>

2.也可以把参数加到my.cnf里面

vim /etc/my.cnf

[mysql]

prompt='\\u@\\h : \\d:\\D>'

##prompt="\\u@\\h :\\d\\r:\\m:\\s>"

[root@zw-test-db ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost : (none) 05:49:40>use test

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

[root@localhost ~]# mysql -uroot -p -S /tmp/mysql3307.sock

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost : (none):Thu Sep 14 19:36:09 2017>use test;

Database changed

root@localhost : test:Thu Sep 14 19:36:15 2017>

参数如下:

Option  Description

\c  A counter that increments for each statement you issue

\D  The full current date

\d The default database

\h The server host

\l The current delimiter (new in 5.1.12)

\m  Minutes of the current time

\n  A newline character

\O  The current month in three-letter format (Jan, Feb, …)

\o  The current month in numeric format

\P  am/pm

\p The current TCP/IP port or socket file

\R  The current time, in 24-hour military time (0–23)

\r  The current time, standard 12-hour time (1–12)

\S  Semicolon

\s  Seconds of the current time

\t  A tab character

\U   www.jb51.net

Your full user_name@host_name account name

\u Your user name

\v  The server version

\w  The current day of the week in three-letter format (Mon, Tue, …)

\Y  The current year, four digits

\y  The current year, two digits

\_  A space

\   A space (a space follows the backslash)

\'  Single quote

\"  Double quote

\\  A literal “\” backslash character

\x

x, for any “x” not listed above

登陆数据库脚本:

[root@localhost ~]# cat /usr/local/bin/db

#!/bin/bash

source /etc/profile

Cmd1='mysql  -h127.0.0.1 -uroot -p'Zykj@558996' -S /tmp/mysql3307.sock -P3307 -Dtest'

Cmd2='mysql  -h127.0.0.1 -uroot -p'Zykj@558996' -S /tmp/mysql3307.sock -P3307 -Ds2166ptzy'

Test(){

${Cmd1} --prompt="[\u@\h:\p(\d) \R:\m:\s] mysql>" --default-character-set=utf8 -A "$@"

RETVAL=$?

return $RETVAL

}

S2166ptzy(){

${Cmd2} --prompt="[\u@\h:\p(\d) \R:\m:\s] mysql>" --default-character-set=utf8 -A "$@"

RETVAL=$?

return $RETVAL

}

case $1 in

test)

Test

RETVAL=$?

;;

s2166ptzy)

S2166ptzy

RETVAL=$?

;;

*)

echo "USAGE: $0 {test|s2166ptzy}"

;;

esac

RETVAL=$?

本文转自 wjw555 51CTO博客,原文链接:http://blog.51cto.com/wujianwei/1965388

mysql --prompt详解_mysql5.6 prompt的用法详解相关推荐

  1. revoke mysql_浅谈MySQL中授权(grant)和撤销授权(revoke)用法详解

    MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利 grant selec ...

  2. mysql revoke 授权_浅谈MySQL中授权(grant)和撤销授权(revoke)用法详解

    MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利 grant selec ...

  3. 给mysql 授权 命令_mysql中授权命令grant用法详解:

    mysql中授权命令grant用法详解: mysql中可以给你一个用户授予如select,insert,update,delete等其中的一个或者多个权限,主要使用grant命令,用法格式为: gra ...

  4. mysql escape关键字_MySQL中ESCAPE关键字的用法详解

    MySQL转义 转义即表示转义字符原来的语义,一个转义字符的目的是开始一个字符序列,使得转义字符开头的该字符序列具有不同于该字符序列单独出现时的语义. MySQL中,转义字符以"\" ...

  5. idea2019配置gradle详解_Constraint Layout 2.0 用法详解

    Constraint Layout 是最受欢迎的 Jetpack 库之一,它的 2.0 正式版本也发布啦 (目前最新版本 2.1.0-alpha1)!也许您已熟悉了 Constraint Layout ...

  6. java if 用法详解_Java if判断语句用法详解

    Java if判断语句用法详解 if关键字中文意思是如果,其细致的语法归纳来说总共有三种:if语句.if-else语句和if-else if-else语句,下面重点介绍if语句. if语句 语法 if ...

  7. mysql的explain怎么看_mysql中explain用法详解

    如果在select语句前放上关键词explain,mysql将解释它如何处理select,提供有关表如何联接和联接的次序. explain的每个输出行提供一个表的相关信息,并且每个行包括下面的列: 1 ...

  8. mysql中find_in_set()函数的使用及in()用法详解

    From: http://www.manongjc.com/article/2710.html MySQL手册中find_in_set函数的语法解释: FIND_IN_SET(str,strlist) ...

  9. mysql的存储过程原理_mysql存储过程原理与用法详解

    本文实例讲述了Mysql存储过程原理与用法.分享给大家供大家参考,具体如下: 本文内容: 什么是存储过程 存储过程的创建 存储过程的使用 查看存储过程 修改存储过程 删除存储过程 首发日期:2018- ...

最新文章

  1. HIve分组查询返回每组的一条记录
  2. ubuntu内核和主线内核_ubuntu上更新和卸载Linux内核
  3. python2.7多线程的批量操作远程服务器
  4. BZOJ3133[Baltic2013]ballmachine
  5. java 反向映射,如何使用lambdas實現反向映射Java?
  6. ThreadLocal 中的ThreadLocalMap
  7. python return用法_初学Python要了解什么 装饰器知识汇总有哪些
  8. Unity Shader 屏幕后效果——Bloom外发光
  9. Docker资源限制
  10. linux 网络命令 dns,[LN_03] Linux网络环境查看(网卡|路由|DNS|IP)、网络测试命令(端口探测|路由跟踪|抓包|ssh连接)...
  11. CSDN中最全python字典和实例,让你轻松掌握
  12. libsvm——数据格式的转换及使用
  13. 在线有道词典,又添新特色了!
  14. 算法竞赛入门经典第11章 无根树转有根树
  15. 道可道,非常道——详解promise
  16. 2.4父子进程虚拟地址空间情况
  17. 1354:括弧匹配检验(C C++)
  18. 数据分析体系 - 用户粘性(DAU/MAU 和 月人均活跃天数)
  19. 一种通俗易懂的PWM的解释
  20. MSP430晶振配置详解

热门文章

  1. “屏男屏女”?!今天你“屏”了吗?
  2. 【解决方案】艾美捷脂肪生成测定试剂盒的功能和应用
  3. 【2021-05-23】7-3 模拟2048游戏(1)--单行向左移动叠加 个人题解
  4. 判断2000年---2500年之间的闰年
  5. 牧牛区块链培训,区块链产业生态已经初步形成
  6. java双斜线转义_转义字符\(在hive+shell以及java中注意事项):正则表达式的转义字符为双斜线,split函数解析也是正则...
  7. 【Java 9】【排序算法】【微信开发】【反钓鱼】【Spring】| Chat · 预告
  8. 天涯明月刀开发_腾讯或为天涯明月刀打造国际研发团队
  9. android写qq聊天界面,30分钟手动实现QQ聊天界面
  10. 超频稳定测试软件,超频第三步:稳定性测试Kombuster