9

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.

3 Answers 3

8

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.

1
  • This works, but sadly also removes the output of number of rows and execution time, e.g. 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
5

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.

1
  • silent will make SELECTs look ugly without boundaries.
    – cronfy
    Feb 29, 2016 at 10:44
2

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.

1
  • 1
    The -s option is smart, but removes the boundaries (signs |, + and -) when executing SELECT-statements. If on *nix; one option is to use an alias and echo a message prior booting mysql. Mar 19, 2014 at 12:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .