Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-06-01 18:28:27 10月05日 Update

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.

Tags: Data database user login user name file configuration host information can be passed more help service different inconvenient one line above below content command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Redmi vpn Xiaomi