MySQL之MySQL:prompt 設置 -登錄MySQL顯示用戶名和主機以及當前數據庫

是開始希望不是結束,是起點希望不是終點html


今天在作MySQL練習過程當中,忽然發現,登錄mysql後,命令行不能顯示用戶名和主機信息,同時呢,想查看數據庫信息還須要查看select datebase()命令查看,特別不方便,所以特別查看了mysql的相關資料,每次經過客戶端登錄怎麼才能顯示這些信息呢?其實MySQL的相關設置都在配置文件my.cnf中能夠設置。所以就去看my.cnf文件,以前就使用下,沒有細心看。my.cnf配置文件中兩大部分:[client]和[mysqld],前者是客戶端的配置參數,後者是服務端的配置參數,既然問題是:客戶端登錄MySQL服務顯示相關信息,那麼配置應該在[client]當中,那麼應該如何設置呢?請看下文一一解答。node

實驗環境:mysql

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

默認狀況鏈接到 mysql 庫後不會顯示當前鏈接的數據庫名。以下圖,sql

wKiom1gdu7eDOCtBAAGM6VTNZq4709.png-wh_50

這樣在登錄MySQL後每次都看不到當前用戶和主機名以及當前的數據庫信息,給維護工做帶來不便。其實在登錄MySQL後能夠經過設置MySQL配置文件的方式,顯示以上信息。方法:修改MySQL配置文件/etc/my.cnf中的[mysqld]中的prompt選項。過程以下:數據庫

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


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

[client]ide

port = 3306學習

socket = /tmp/mysql.sock測試

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

#character_set_server = utf8

#character_set_client = utf8

[mysqld]備註:設置後重啓MySQL 服務。 \u 表示用戶名,  \h 表示主機名, \d 表示當前數據庫。

設置格式能夠添加相關符號好比[]等

(2)重啓 MySQL 服務 

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

Shutting down MySQL...... SUCCESS!

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

(3)鏈接測試

[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>

說明:

關於配置文件/etc/my.cnf的修改中,prompt選項,能夠經過幫助文檔查看

--prompt 更多設置能夠查看MySQL命令幫助

謝謝你們的閱讀,技術學習之路還很長,願與你一塊兒成長!

相關文章
相關標籤/搜索