I need to connect to a MySQL database on a server to which I do not have access through the firewall. I do however have SSH access to another server which is allowed through the firewall on my target server.

I have SSH'd into the latter (let's say host1) and then I am attempting to execute the following command:

mysql --host=host2 --user=username --password=password

I get the following response:

Access denied for user 'username'@'host1' (using password: YES)

Why is it trying to connect to host1 (i.e itself)?

NB: I'm not using localhost anywhere here.

  • I don't understand the down vote. It's a legitimate misunderstanding. If I knew the reason, I wouldn't need to ask the question. – Matt Harrison Jun 7 '13 at 10:15

You are misunderstanding the error, it is saying that the user username connecting from host1 was denied access. The error comes from host2.

  • Thanks, I didn't realise it was an error coming from host 2. – Matt Harrison Jun 7 '13 at 10:20

The error is actually saying "You're trying to use username from host1".

You'll need to add permissions for username on host1. Can you post SHOW GRANTS FOR 'username' from while logged into MySQL as root on host2?

Edit: Ninja'd :)

  • Sorry bout that :) – NickW Jun 7 '13 at 9:53

I had this error because of the wrong password I used for the database. This was the case for the Version Version of mysql is 5.1.61.

So ensure the password of your database is correct.

  • In this case, the accepted answer is correct. This can be the cause of that error, yes, but that wasn't the question. – Falcon Momot Mar 11 '14 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.