欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql prompt的用法详解

程序员文章站 2024-02-24 08:45:10
prompt命令可以在mysql提示符中显示当前用户、数据库、时间等信息复制代码 代码如下:mysql -uroot -p --prompt="\\u@\\h:\\d \\...
prompt命令可以在mysql提示符中显示当前用户、数据库、时间等信息
复制代码 代码如下:

mysql -uroot -p --prompt="\\u@\\h:\\d \\r:\\m:\\s>"

设置成功后:
复制代码 代码如下:

welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 5
server version: 5.1.60-log source distribution
copyright (c) 2000, 2012, 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) 11:04:23>

也可以在在my.cnf配置文件里进行配置:
复制代码 代码如下:

[mysql] 
prompt=mysql(\\u@\\h:\\d)> 

default-character-set=utf8 

选项说明:
复制代码 代码如下:

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