I am running the following command to connect to a remove mysql server (it is part of a bash script that will connect automatically)

mysql -h slave1 -u monitor -pvP!KnK4*

And I receive the following response within the terminal window

-bash: !KnK4: event not found

When I run mysql -h slave1 -u monitor -p without adding the passing in the command line and use the same password when prompted to enter it in this works fine.

What am I doing wrong in this instance?

PS the password above is not the real password (it is much longer just made it smaller for stackexchange purposes)

  • apparently bash treats everyting before the ! sign, namely "pvP" in your case, as options. Try to add a space after "-p". And better don't use the "-p" option on a live server, since the password remains in the bash history and can be stolen
    – d.k
    Apr 11, 2019 at 15:43
  • tried the space and it still doesn't seem to work :(
    – Zabs
    Apr 11, 2019 at 15:44
  • did you try quotes?
    – d.k
    Apr 11, 2019 at 15:44
  • characters like ! and * can well be special to bash. So use them in single quotes
    – d.k
    Apr 11, 2019 at 15:45

1 Answer 1


If you are going to use characters that are special to the shell (e. g. !, *) as a portion of a parameter, you must present it in such a manner as to not be interpreted by the shell before it is passed to the command you're invoking.

Rather than:

$ mysql -h slave1 -u monitor -pvP!KnK4*

Instead use:

$ mysql -h slave1 -u monitor -p'vP!KnK4*'

And then, when you have a moment, change your MySQL user's password if this is your actual password because you have put it on the internet for all to see.

(As a further aside, you should be aware that anyone who is able to read your user's shell history file also has access to this password.)

  • will try that (the pwd itself is different just similar syntax although much longer)
    – Zabs
    Apr 11, 2019 at 15:46
  • 1
    Glad to hear this is not your actual password.
    – DopeGhoti
    Apr 11, 2019 at 15:47

You must log in to answer this question.

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