Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up prompt to realize login MySQL display user name and current database

2025-04-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following brings you about prompt how to set up the login MySQL to display the user name and the current database content, I believe you must have seen similar articles. What's the difference between what we bring to everyone? Let's take a look at the body. I believe you will gain something after reading how to set up prompt to log in to MySQL to display the user name and the current database.

Experimental environment:

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

By default, the database name of the current connection is not displayed when you connect to the mysql library. The figure below is as follows

In this way, the current user and host name and the current database information can not be seen every time after logging in to MySQL, which brings inconvenience to the maintenance work. In fact, after logging in to MySQL, you can display the above information by setting the MySQL configuration file. Method: modify the prompt option in [mysqld] in the MySQL configuration file / etc/my.cnf. The process is as follows:

(1) Open the configuration file of MySQL: edit / etc/my.cnf and add the following line in red as below

[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] Note: restart the MySQL service after setting. \ u represents the user name,\ h represents the host name, and\ d represents the current database.

If you set the format, you can add related symbols such as [], etc.

(2) restart MySQL service

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

Shutting down MySQL. SUCCESS!

Starting MySQL. SUCCESS!

(3) connection test

[root@dbnode1] # 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.

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 >

Description:

In the modification of the configuration file / etc/my.cnf, the prompt option can be viewed through the help documentation.

-- prompt more settings can be found in the MySQL command help

For the above about prompt how to set up the login MySQL display user name and the current database, do you think it is what you want? If you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report