2

I'm trying to run a MySQL command from a bash script:

mysql --user=[USER] --password=[PASSWORD] --database=[DATABASE] --execute="DELETE FROM table WHERE created_at < NOW() - INTERVAL 7 DAY"

Both in the bash script and terminal, I get the same error:

ERROR 1045 (28000): Access denied for user '[USER]'@'localhost' (using password: YES)

I've tested running mysql -u [USER] -p and that will connect so I know my credentials are correct.

What am I missing? I've seen a few things online suggesting the port may be wrong, but it's all set running on localhost, which is correct

3
  • Do you have modify permissions for that database or table? Commented Aug 14, 2014 at 2:06
  • acutally, i've just figured it out: there's a $ in my password which bash is trying to interpret as a variable. Is there a way to escape the $ rather than changing my password? Commented Aug 14, 2014 at 2:09
  • Using Single quotes around your password? Commented Aug 14, 2014 at 2:18

2 Answers 2

3

figured it out. The problem wasn't the permissions, but the password itself. I needed to escape a $ in my password, so the code changed to the following (using the password pass$word):

mysql --user=[USER] --password=pass\$word --database=[DATABASE] --execute="DELETE FROM table WHERE created_at < NOW() - INTERVAL 7 DAY"

works like a charm now.

Sign up to request clarification or add additional context in comments.

Comments

1

1.maybe you should check into your mysql table mysql.user if USER and localhost in this table, if no add your USER

2.check your USER privileges if USER has right to get into this databases.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.