標籤:使用者名稱 主機 資料庫 prompt my.cnf
是開始但願不是結束,是起點但願不是終點
今天在做MySQL練習過程中,突然發現,登陸mysql後,命令列不能顯示使用者名稱和主機資訊,同時呢,想查看資料庫資訊還需要查看select datebase()命令查看,特別不方便,因此特別查看了mysql的相關資料,每次通過用戶端登陸怎麼才能顯示這些資訊呢?其實MySQL的相關設定都在設定檔my.cnf中可以設定。因此就去看my.cnf檔案,之前就使用下,沒有細心看。my.cnf設定檔中兩大部分:[client]和[mysqld],前者是用戶端的配置參數,後者是服務端的配置參數,既然問題是:用戶端登陸MySQL服務顯示相關資訊,那麼配置應該在[client]當中,那麼應該如何設定呢?請看下文一一解答。
實驗環境:
[[email protected] ~]# cat /etc/redhat-release CentOS release 6.5 (Final)
MySQL版本:Server version: 5.6.33-log MySQL Community Server (GPL)
預設情況串連到 mysql 庫後不會顯示當前串連的資料庫名。如,
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M00/89/D1/wKiom1gdu7eDOCtBAAGM6VTNZq4709.png-wh_500x0-wm_3-wmp_4-s_2876509457.png" title="1 2016-11-05_184627.png" alt="wKiom1gdu7eDOCtBAAGM6VTNZq4709.png-wh_50" />
這樣在登陸MySQL後每次都看不到目前使用者和主機名稱以及當前的資料庫資訊,給維護工作帶來不便。其實在登陸MySQL後可以通過設定MySQL設定檔的方式,顯示以上資訊。方法:修改MySQL設定檔/etc/my.cnf中的[mysqld]中的prompt選項。過程如下:
(1)開啟MySQL的設定檔:編輯/etc/my.cnf 添加以下如下紅顏色一行
[[email protected] ~]# vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
prompt="\\[email protected]\\h:\\d>"
#character_set_server = utf8
#character_set_client = utf8
[mysqld]備忘:設定後重啟MySQL 服務。 \u 表示使用者名稱, \h 表示主機名稱, \d 表示當前資料庫。
設定格式可以添加相關符號比如[]等
(2)重啟 MySQL 服務
[[email protected] ~]# /etc/init.d/mysql restart
Shutting down MySQL...... SUCCESS!
Starting MySQL.................. SUCCESS!
(3)串連測試
[[email protected] ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server 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 itsaffiliates. Other names may be trademarks of theirrespectiveowners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clearthe current input statement.
[email protected]:(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
[email protected]: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
[email protected]:test>
說明:
關於設定檔/etc/my.cnf的修改中,prompt選項,可以通過協助文檔查看
--prompt 更多設定可以查看MySQL命令協助
謝謝大家的閱讀,技術學習之路還很長,願與你一起成長!
本文出自 “堅持不懈IT男” 部落格,請務必保留此出處http://it3246.blog.51cto.com/7479386/1869838
MySQL之MySQL:prompt 設定 -登陸MySQL顯示使用者名稱和主機以及當前資料庫