[MySQL tips] customize your MySQL Command Line

Source: Internet
Author: User

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

The command line after I log on to MySQL looks like this:

Warmbupt @ pchuang:/Windows/mycode/SS $ mysql-u root-ppassw0rd
Welcome to the MySQL monitor. commands end with; or/g.
Your MySQL connection ID is 37
Server version: 5.1.37-1ubuntu5. 1 (UBUNTU)
Type 'help; 'or'/H' for help. type'/C' to clear the current input statement.
Mysql>

Through a series of transformations, we can get a command line prompt that is more user-friendly.

We try to display the username, host name, and database name in use:

Set the environment variable in the shell command line:

Export mysql_ps1 = "/u @/H [/d]>"
Where
  • /U-username Username
  • /H-hostname Host Name
  • /D-current MySQL Database Current Database

Of course, you can write this command to bashrc and then use it in Bash to get such a command line prompt. Or you can set it in the MySQL configuration file/etc/My. CNF or. My. CNF:

prompt=//u@//h [//d]>//_

In addition, you can also set the following in MySQL:

Prompt/u @/H [/d]>

When you want to restore the original data, you can type prompt in MySQL to return to the regression (back to the settings outside MySQL, if you write in bashrc, it will return to the setting state in bashrc ).
Variable table attached:

Generic variables:

  • /S displays semicolon
  • /'Displays single quote
  • /"Displays double quote
  • /V displays server version
  • /P displays Port
  • // Displays backslash
  • /N displays newline
  • /T displays Tab
  • /Displays space (there is a space after /)
  • /D displays default database
  • /H displays default host
  • /_ Displays space (there is a underscore after /)
  • /C displays a MySQL statement counter. keeps increasing as you type commands.
  • /U displays Username
  • /U displays username @ hostname accountname

Date related variables:

  • /D displays full current date (as shown in the above example)
  • /W displays 3 letter day of the week (e.g. Mon)
  • /Y displays the two digit year
  • /Y displays the four digit year
  • /O displays month in number
  • /O displays 3 letter month (e.g. Jan)
  • /R displays current time in 24 hr format
  • /R displays current time in 12 hour format
  • /M Displays the Minutes
  • /S displays the seconds
  • /P displays am or PM

 

Author: gnuhpc

Source: http://www.cnblogs.com/gnuhpc/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.