2
0
I'm trying to connect to mysql using the command
mysql -h 127.0.0.1
It comes up with the error
ERROR 1045 (28000): Access denied for user 'root'@'mydomain.com' (using password: NO)
Why is 127.0.0.1 being converted into my domain name, and how can I fix it?
However, it does work if I don't specify a host (and by extension, if 'localhost' is specified).
Edit: It seems it resolves to the domain name when using TCP, so it also fails when using
mysql -h localhost --protocol=TCP
Edit2: When I use skip-name-resolve I get a similar output except mydomain.com
is replaced with x.x.x.x
which is the public IP of mydomain.com
.
Assuming you're on a Unix/Linux machine - have you got
127.0.0.1 mydomain.com
in your/etc/hosts
file? – garethTheRed – 2014-07-04T08:51:26.930I had tried that, but it didn't yield any difference – Ben – 2014-07-04T11:03:47.060
No difference as in it still said
Access denied
or it still hasmydomain.com
in the user name? If it's the latter and you definitely have removed your hostname from/etc/hosts
then DNS must be misconfigured formysql
to be able to reverse lookup127.0.0.1
to your hostname. – garethTheRed – 2014-07-04T11:11:10.830No difference as in the error output was exactly the same with or without that in
/etc/hosts
– Ben – 2014-07-04T11:32:39.190This answer contains hints as to finding a solution. – Daniel B – 2014-07-04T12:12:22.667
@DanielB I mentioned in the first edit that the issue seemed to be for TCP connections. I can however
telnet 127.0.0.1 3306
which shows that mysqld is listening and accessible. I can also explicitly add a'root'@'mydomain.com'
user and login to mysql. – Ben – 2014-07-04T12:23:08.877@user3603149 : Did you checked whether you have provided user root with proper privilege and password – Renju Chandran chingath – 2014-07-04T12:48:31.717
@RenjuChandranchingath logging in is not the direct issue. The issue is that any attempts to connect using
mysql -h 127.0.0.1
are not seen as coming from localhost or 127.0.0.1 but something else (in this case the hostname of (or) the public IP) – Ben – 2014-07-04T12:53:36.360@garethTheRed I added Edit2 which suggests that rDNS is not the cause. It seems more like an
iptables
issue but I've tried flushing unnecessary rules etc to no avail. – Ben – 2014-07-04T13:29:35.947Are you using a password? mysql -h 127.0.0.1 -uroot -pMyRootPassword
actually works as intended. – None – 2014-07-04T06:35:41.337
The password is irrelevant. If I added 'root'@'mydomain.com' as a user it would work, but I want to connect using 'root'@'127.0.0.1'. The problem is that any mysql TCP connection made to either 127.0.0.1 or localhost gets changed into mydomain.com – Ben – 2014-07-04T06:41:06.467
You forgot to state your operating system and MySQL version. – Michael Hampton – 2014-07-04T14:31:51.810