mysqldump – Using password: NO error
I need to back up a mysql database on a shared hosting server. I am using the cron job to run a bash file which runs a mysqlcommand. The problem is that I can’t get MySQL to recognize the password. I have no spaces after the “-p” however, I still get the following error:
mysqldump: Got error: 1045: Access denied for user ‘some_user’@’localhost’ (using password: NO) when trying to connect
No thanks to JustHost of course. They don’t know why this doesn’t work as one support member tried to help me, but stopped replying after all his solutions failed and another support member just plain said “we do not provide support for this issue”.
On to the solution. The problem is that the mysql configuration file on JustHost is set to not supply a password no matter what you pass into the mysqldump command. I’m not sure of the specifics of this so you can read more on configuration files if you need more details. The key that clued me into the problem was a comment on this page. He had a similar problem to what I was having. In the end my cnf file looked like below, named “mymysql.cnf”:
[client] # The following password will be sent to all standard MySQL clients password="thePassword"
And my bash file looked like so:
#!/bin/bash mysqldump --defaults-file=/somedir/mymysql.cnf -u theusername thedbname > /somedir/thedbname`date +%d`.sql
keywords: access denied using password NO