简体   繁体   中英

MySQL ERROR 1045 in bash script - access denied

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM