Reputation: 839
I know it looks like a duplicate question, but I tried a couple of things and they still didn't work.
I want to connect to mysql on a machine 10.9.244.43
from another machine 10.102.5.83
. But when I try to mysql -h10.9.244.43 -uroot -p
, I get the following error:
ERROR 2003 (HY000): Can't connect to MySQL server on '10.9.244.43' (111)
I checked and commented bind-address in /etc/mysql/my.cnf. But it still not able to connect.
When I tried the following commands on 10.9.244.43:
SELECT USER(),CURRENT_USER();
I got:
+----------------+----------------+
| USER() | CURRENT_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
When I tried:
SHOW GRANTS;
I got the following:
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*E7C06D40357612837106427CD0F2B2058' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
How should I fix this?
Upvotes: 1
Views: 839
Reputation: 1075
if you want to connect as root from a different machine (bad idea) you want to grant the privilege to 'root'@'%' and not 'root'@'localhost'.
'root'@'localhost' only allows root to connect from the local machine. 'root'@'%' allows root on any host to connect, note these are different users, just because the account is called root on both servers does not make them the same account, that's why you need to allow access from any machine.
if you are always connecting from a specific machine you can also assign the privilege to 'root'@'10.102.5.83' but that can be tricky sometimes, depending on how hostname is defined and public IP addresses, etc...
other things to test are firewalls and the bind address.
If you do open access to the world using 'root'@'%', you should limit access by firewall once you have your setup working.
Finally, keep in mind that these are two separate privileges, so you can actually assign 'root'@'%' different privileges than 'root'@'localhost', for example to remove ability to drop tables, alter tables, etc...
Upvotes: 1