Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. 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

I am trying to set a cron job for taking backup from my slave machine. So I need to stop the slave

I issued a command

mysqladmin --user=root --password=test_pass stop-slave

But it is throwing error:

mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'

Now I tried with the command

mysqladmin --user=root --password stop-slave

It prompts for password and I gave as test_pass and everything was fine.

Why so happened? What is the alternative?

NB: BTW my mysql version is mysql-5.0.95-5, it it make any sense.

share|improve this question
Does your password have any special characters that the shell might be interpreting? Have you tried enclosing the password in 'quotes' or "quotes"? – Michael - sqlbot Aug 27 '13 at 10:47
which are the special characters that shell might get interpreting? is there any documentation? – Praveen Prasannan Aug 27 '13 at 10:54
Characters like $ & ! \ [ ] < > all come to mind as potentially problematic. Enclosing the password in ' single quotes should prevent that problem. – Michael - sqlbot Aug 27 '13 at 11:08
great.. working. I would like to mark this as answer. Can u please put it as answer – Praveen Prasannan Aug 27 '13 at 11:19
@Michael-sqlbot yes you should post is as the answer – RolandoMySQLDBA Aug 27 '13 at 13:42
up vote 9 down vote accepted

Command line arguments are subject to interpretation by the system's command shell, changing the behavior of the command or changing the value of the arguments before they are passed into the called program.

When an argument (such as the value for --password) contains an character that the shell may interpret, they need to be either quoted (usually enclosed in single quotes ' in unix or double quote " in Windows) or escaped individually (usually with a backslash \ before each metacharacter) to avoid interpretation by the shell.

While the specific characters are system-specific, some characters to watch out for include:

$ & ! \ [ ] < > `

If the password, for a really bad example, were set to pa$$word ...

mysql --password=pa$$word     # does not work
mysql --password='pa$$word'   # works
mysql --password=pa\$\$word   # works, but slightly unclear what's going on at first glance

Further reading:

Update: to escape either ' single or " double quotes in the password, you can either escape them with a leading backslash, or enclose the entire argument in the opposite style of quotes if there are no other characters that the chosen style of quoting isn't compatible with.

mysql --password="like'this" # password has a single quote in the middle
mysql --password='like"this' # password with a double quote in the middle

If you have a single quote and other special characters as well, you're stuck with backslash escaping because, in unix, the double quote is "weaker" than a single quote and many metacharacters are still expanded when enclosed in double quotes but not single quotes.

This is not MySQL-specific but applies to anything with command line arguments.

You can typically use the echo command to see how the shell is interpreting your arguments.

$ echo foo$bar 
foo                # literal 'foo' plus the (empty) shell variable $bar

$ echo foo\$bar
foo$bar            # backslash prevents expansion of $bar as a variable

$ echo "foo$$bar"  # weaker double quote doesn't prevent expansion so
foo9691bar         # the $$ expands to the unix process id (pid) of the current shell

$ echo 'foo$$bar'
foo$$bar           # "stronger" single quote prevents shell expansion

$ echo "foo'bar"
foo'bar            # double quote allows single quote within the literal
share|improve this answer
Need a little more clarification. What if single quotes (') coming in password field? Escaping it with slash() is the only way? – Praveen Prasannan Aug 27 '13 at 16:09

Your Answer


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.