Today, while search for how to execute the SQL
statements in a text file from the
mysql client program I also learned how to
change the mysql prompt using the
command (short version
For example the following command will show the current database name between parentheses in the prompt, which is quite useful if you switch often between databases:
mysql> prompt mysql (\d)>
Note that if you type an additional space after the > character, your prompt will have that additional space as well.
Besides \d, which shows the current database, there are many more special sequences, see the official mysql commands documentation.
To make this prompt permanent you can:
environment variable, for example via your
.bashrc file using:
export MYSQL_PS1="mysql (\d)> "
Add it to the [mysql] group of a MySQL
option file, for example
/etc/my.cnf or the
.my.cnf in your home
directory. For example:
[mysql] prompt=mysql (\d)>
Create an alias in, for example your
.bashrc file, that uses the
--prompt option of the
mysql command to set the prompt. For
alias mysql='mysql -uroot -p --prompt="mysql (\d)> "'
I came upon this "secret" when looking for a way to execute the statements in a text file from within the mysql client program. Maybe I should take some time to study the documentation of this program that I use quite often.
Anymore useful mysql client program tips? Please post a comment, thanks.