Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

Add following in your my.cnf

[mysql]
silent

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.

share|improve this answer
    
silent will make SELECTs look ugly without boundaries. – cronfy Feb 29 at 10:44

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.

share|improve this answer
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. – mira_mayhem Mar 19 '14 at 12:06

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.