When I connect from the commandline, is it possible to change the welcome message displayed by MySQL?
The current message displays the version, Oracle copyright, etc.
I would also like to display a banner.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityTo remove welcome message, use --silent
switch. But it will also make output nontabular (SELECT's output without boundaries) which looks ugly. To bring tabular output back, use --table
switch.
mysql --silent --table -u user_name -p db_name
# or short form
mysql -s -t -u user_name -p db_name
To print your own welcome message, create a script, say, mysql.sh
, and use echo
to print your banner. Run this script instead of mysql
.
Example script:
#!/usr/bin/env bash
echo "Welcome to mysql!"
# "$@" will pass script arguments to mysql.
mysql -s -t "$@"
Usage:
./mysql.sh -u user_name -p db_name
You can use bash aliases or functions to substitute mysql
command with your script, i. e. (assuming you put mysql.sh
into your $HOME/bin/
):
alias mysql=$HOME/bin/mysql.sh
Then mysql -u user_name -p -db_name
will run your script, that will print your banner and run mysql.
1 row in set (0.00 sec)
for a select, or Query OK, 0 rows affected (0.00 sec) Rows matched: 34 Changed: 0 Warnings: 0
for an update.
Sep 19, 2022 at 15:52
Add following in your my.cnf:
[mysql]
silent
or add --silent to your mysql CLI
and try logon trigger to print the banner via "system echo 'my custom message'". With some more creativity, you can customize per user logon message.
At the very least, you could suppress the welcome message using the -s
or --silent
option
# mysql -u... -p -s
It will immediately present the mysql prompt
mysql>
Perhaps, you may want to create a shell script with the custom welcome or banner that displays prior to logging into mysql.
If you are a little more daring, you could download the source, locate and change the welcome message, recompile all binaries, and install. If you are that daring, have fun with that one.