SSH remote execute command with special characters

You can try escaping the special characters in the command that you are passing to the ssh. In which case your

p$ssw0rd

becomes

p\$ssw0rd

Since the shell you are using might interpret "\" character differently, I can not vouch for 100% solution to your case, but it won't hurt to try.


Why don't you just specify your credentials in an options file?

Edit ~/.my.cnf and add something like this:

[mysql]
user = 'dbname'
password = 'p$ssw0rd'

Make sure you run $ chmod 600 ~/.my.cnf to restrict access to that file.

Then you don't need to specify those in your SSH command. This is arguably a safer way to do thing anyway, as usernames/passwords don't show up in either your ~/.bash_history or the running process list (which is viewable by all users).