runlevel0
runlevel0

Reputation: 2993

How to change the MySQL prompt from the command line

I bet this is easy and I have surely overseen something:

I am trying to set the "internal" MySQL prompt from the Bash shell as an argument to the command mysql.

The manual makes reference a command line option called --named-command=str where I assumed that I could pass any of the commands referred here:

mysql Command-line Client

But an version of the command below return an error after connecting to the DB:

mysql --named-commands='\R >'
mysql --named-commands="\R >"

The error reads:

Warning: mysql: ignoring option '--named-commands' due to invalid value '\R > '

I thus assume that I am missing something. Please note that I have already gone through the MySQL manual/s (both, the Oracle site and the MariaDB site). The fact is that the question itself is not easy to define as when I t yto google for "Mysql Command line option" it normally takes me to the "internal" MySQL command line (or more exactly, the MySQL command line client).

Thanks for your suggestion :)

Upvotes: 0

Views: 1063

Answers (2)

For example, using --prompt= or --prompt, you can change the default prompt mysql> to 11> with login as shown below. *\R is the current time, in 24-hour military time (0–23) according to the doc and my answer explains how to change the default prompt mysql> in detail:

mysql -u john -p --prompt='\R> '
...
11>

Or:

mysql -u john -p --prompt '\R> '
...
11>

Upvotes: 0

enharmonic
enharmonic

Reputation: 2118

mysql -h hostname -u username -p --prompt myCustomPrompt\>

Be sure to escape > with \ in order to avoid a bash syntax error. See the final section of mysql client commands for instructions on special characters to use in the prompt command.

Upvotes: 1

Related Questions