Is it possible to change the mysql welcome message?

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.


Solution 1:

To 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.

Solution 2:

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.