Detailed explanation of MySQL prompt usage

Time:2022-4-29

When we configure mysql, which instance of MySQL we want to use to connect to the MySQL system, and which of the following information we need to use when we configure the MySQL instance of prompt, and so on:

1. We can put it in the MySQL project of the default configuration file. When we log in, we can see that our configuration information is displayed as scheduled:

[email protected]:~# more /etc/my.cnf
[mysql]
prompt="\\[email protected]\\h [\\d]>"
[email protected]:~# mysql -S /tmp/mysql3306.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

[email protected] [(none)]>

2. If our configuration file is not the default configuration file, we need to specify the configuration file when logging in. You can also:

[email protected]:~# mysql --defaults-file=/etc/myback.cnf -S /tmp/mysql3306.sockWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

[email protected] [(none)]>

3. If we only use it temporarily and don’t want to create or modify the configuration file, we can directly specify the parameters when logging in:

[email protected]:~# mysql -S /tmp/mysql3306.sock --prompt="\\[email protected]\\h [\\d]>"

Next, let’s sort out which information can be customized and which character corresponds to what information:

\C The identifier of the current connection, that is, the ID of the current connection can be seen from the show processlist
\c Statement counter per new connection execution
\D Current complete time, including mm / DD / YY, hour, minute and second
\d The current database, such as user test, displays test. If the use command is not executed, it displays (none)
\h Instance connection address
\l “;” Delimiter, which can be used between multiple configurations
\m Current time minutes
\n Line feed
\O Three letter month
\o Month in numeric format
\P Morning afternoon
\p Current TCP / IP port
\R Current time: 24 hours
\r Current time hours, 12 hour system
\S semicolon
\s Current time seconds
\t Tab
\U Full account name user_ [email protected]_name
\u User name user_ name
\v MySQL server version
\w Current day of week
\Y Current 4-digit year
\y Current 2-digit year
\_ Space
\  
\’ Single quotation mark
\” Double quotation mark
\\  
\x  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In fact, most of the parameters we use everyday may be user name, connection address, database name, time and other parameters, which can be customized according to needs;