mysql prompt用法詳解


  當我們用mysql client連接mysql實例的時候我們想要顯示我們連接的是那個實例、用哪個賬號登錄的、現在在哪個database中、現在系統時間等等很多信息的時候,那么mysql prompt將需要配置,以下將介紹prompt的配置詳解,以及配置方法:

1、我們可以放在默認配置文件的mysql項目中,當我們登錄的時候我們就可以看到如期顯示了我們配置的信息:

root@DESKTOP-1T4MD6P:~# more /etc/my.cnf
[mysql]
prompt="\\u@\\h [\\d]>"
root@DESKTOP-1T4MD6P:~# mysql -S /tmp/mysql3306.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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)]>

2、如果我們的配置文件不是默認配置文件,那么我們登錄的時候需要指定配置文件也可以:

root@DESKTOP-1T4MD6P:~# mysql --defaults-file=/etc/myback.cnf -S /tmp/mysql3306.sockWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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)]>

3、如果我們只是臨時用一下不想創建或者修改配置文件,那么我們可以在登錄的時候直接指定參數:

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  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

其實我們日常用的比較多的可能就是用戶名、連接地址、數據庫名、時間等參數,可以根據需求定制;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM