溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

prompt如何設(shè)置實(shí)現(xiàn)登陸MySQL顯示用戶名及當(dāng)前數(shù)據(jù)庫(kù)

發(fā)布時(shí)間:2020-05-28 16:55:08 來源:網(wǎng)絡(luò) 閱讀:299 作者:三月 欄目:數(shù)據(jù)庫(kù)

下文給大家?guī)碛嘘P(guān)prompt如何設(shè)置實(shí)現(xiàn)登陸MySQL顯示用戶名及當(dāng)前數(shù)據(jù)庫(kù)內(nèi)容,相信大家一定看過類似的文章。我們給大家?guī)淼挠泻尾煌兀恳黄饋砜纯凑牟糠职?,相信看完prompt如何設(shè)置實(shí)現(xiàn)登陸MySQL顯示用戶名及當(dāng)前數(shù)據(jù)庫(kù)你一定會(huì)有所收獲。

實(shí)驗(yàn)環(huán)境:

[root@dbnode1 ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
MySQL版本:
Server version: 5.6.33-log MySQL Community Server (GPL)

默認(rèn)情況連接到 mysql 庫(kù)后不會(huì)顯示當(dāng)前連接的數(shù)據(jù)庫(kù)名。如下圖,

prompt如何設(shè)置實(shí)現(xiàn)登陸MySQL顯示用戶名及當(dāng)前數(shù)據(jù)庫(kù)

這樣在登陸MySQL后每次都看不到當(dāng)前用戶和主機(jī)名以及當(dāng)前的數(shù)據(jù)庫(kù)信息,給維護(hù)工作帶來不便。其實(shí)在登陸MySQL后可以通過設(shè)置MySQL配置文件的方式,顯示以上信息。方法:修改MySQL配置文件/etc/my.cnf中的[mysqld]中的prompt選項(xiàng)。過程如下:

(1)打開MySQL的配置文件:編輯/etc/my.cnf 添加以下如下紅顏色一行


[root@dbnode1 ~]# vi /etc/my.cnf


[client]


port = 3306


socket = /tmp/mysql.sock


prompt="\\u@\\h:\\d>"


#character_set_server = utf8


#character_set_client = utf8

[mysqld]備注:設(shè)置后重啟MySQL 服務(wù)。 \u 表示用戶名,  \h 表示主機(jī)名, \d 表示當(dāng)前數(shù)據(jù)庫(kù)。

設(shè)置格式可以添加相關(guān)符號(hào)比如[]等

(2)重啟 MySQL 服務(wù) 

[root@dbnode1 ~]# /etc/init.d/mysql restart

Shutting down MySQL...... SUCCESS!

Starting MySQL.................. SUCCESS!

(3)連接測(cè)試

[root@dbnode1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.33-log MySQL Community Server(GPL)
 
Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks of theirrespective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

root@localhost:(none)>use mysql

Reading table information for completion of tableand column names

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

 

Database changed

root@localhost:mysql>use test

Reading table information for completion of tableand column names

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

 

Database changed

root@localhost:test>

說明:

關(guān)于配置文件/etc/my.cnf的修改中,prompt選項(xiàng),可以通過幫助文檔查看

--prompt 更多設(shè)置可以查看MySQL命令幫助

對(duì)于上文關(guān)于prompt如何設(shè)置實(shí)現(xiàn)登陸MySQL顯示用戶名及當(dāng)前數(shù)據(jù)庫(kù),大家覺得是自己想要的嗎?如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI