In hive, I can set the prompt to be the currently selected database. Is it possible to do the same in MySQL?
I want to replace mysql
with kundoor
in the image below.
In hive, I can set the prompt to be the currently selected database. Is it possible to do the same in MySQL?
I want to replace mysql
with kundoor
in the image below.
Type this in your terminal
export MYSQL_PS1="\u@\h [\d]> "
This will create the following
user@host [databasename]>
In addition to using the MYSQL_PS1 environment variable @Noob describes, you can use the prompt
command within the mysql client:
mysql> prompt \u@\h [\d]
(type a space at the end of the line to get a space after the prompt)
See https://dev.mysql.com/doc/refman/5.7/en/mysql-commands.html for more on mysql client commands.
You can make this default by editing your MySQL options file:
[mysql]
prompt \u@\h [\d]
For example, using
--prompt=
(--prompt
), you can change the default promptmysql>
toapple>
ofapple
database with login as shown below. *\d
is the current database but if the current database is not selected,\d
is(none)
and\_
is a space according to the doc:Or:
Or:
Or, using
just after
prompt
(PROMPT
) or\R
, you can change the default promptmysql>
toapple>
ofapple
database after login as shown below. *Don't forget to put a space\d>
:Or:
Or:
Or:
Or on Windows, you can set the prompt under
[mysql]
inmy.ini
as shown below. *My answer explains[mysql]
and my answer explains wheremy.ini
is located on Windows:Or:
Or:
Then, you can change the default prompt
mysql>
toapple>
ofapple
database with login by settingmy.ini
's location to--defaults-file=
or--defaults-extra-file=
as shown below. *--defaults-file=
or--defaults-extra-file=
must be the 1st option otherwise there is the error:Or: