How might one escape the exclamation point in a password:
$ mysql -umyuser -pone_@&!two
-bash: !two: event not found
Trying the obvious backslash did not help:
$ mysql -umyuser -pone_@&\!two
[1] 22242
-bash: !two: command not found
[email protected] [~]# ERROR 1045 (28000): Access denied for user 'myuser'@'localhost' (using password: YES)
All my google searches suggest that the backslash would help, but it does not. There is no way to use quotes as suggested in this question. The line will be used in a .bashrc alias. Don't worry, the usernames and passwords shown here are examples only and not used in production!
Use single quotes around the password like this:
-p'one_@&!two'
To put it in an alias, you'd do something like:
alias runmysql='mysql -umyuser -p'\''one_@&!two'\'''
You also need to escape the
&
character:If you never use the ! history features, it might be more convenient to simply disable them (with
set +H
in your bashrc).You can store the password in a bash variable:
Then substitute the variable in the command: