Unable to connect to remote mysql server

I have a server trying to connect to a MySQL database hosted outside the local network. I am trying to use a public IP address to connect to it.

Testing the connection on the command line gives me this error:

ERROR 2003 (HY000): Can't connect to MySQL server on '[ip_address]' (146)

PDO gives me the same error. In any case, the connection works fine locally and within the same network, which scares my mind.

The MySQL server has its own binding address, so it accepts remote connections. The MySQL server also has a user with privileges set. But in any case, it seems that I can’t even start the connection in the first place.

Is there a value of my.cnf that needs to be added so that MySQL accepts requests from outside the local network?

Thank.

+3
source share
4 answers

What you need to check:

  • MySQL listens to public IP (sounds like you did)
  • MySQL is listening on the standard port / you are connecting the same port it is listening on.
  • Is there a firewall on the remote computer? (Usually they are standardized on distributions) Is the firewall configured to connect to this port?
  • If the remote computer is on a different network, is there a network address translation (NAT) between your connection and the destination computer - if so, it is configured to allow access to the MySQL port.
  • Is the file configured my.cnffor permissions to connect to anything other than localhost 127.0.0.1IP addresses - although you’ll probably get an access denied response than you can’t connect.
+4
source

. , % ( wild card) .

+2

,

CHECK ALL PRIVILEGES. TO 'root' @ 'localhost' IDENTIFIED by "root" with the GRANT option; GRANT ALL PRIVILEGES. TO 'root' @ '%' IDENTIFIED BY "root" with the GRANT option; PRIVILEGES OF FLUSH;

Now go to the my.cnf file. To use ubuntu (sudo find / -type f -name "my.cnf")

comment out the line "bind-address = 127.0.0.1"

restart mysql using To use ubuntu use "sudo service mysql restart"

0
source

Source: https://habr.com/ru/post/1764181/


All Articles