Re: Can't connect to MySQL database if I use IP instead of "localhost" in the connection URL
Hello Hol,
Routing traffic is something you should research a bit on your own. Exposing any database to the entire internet is usually a "bad idea". Hiding it behind some strange port number is just considered "security by obscurity" and that's not really doing much.
For a more secure deployment, you need some kind of break between the web and your internal resources. This is sometimes a web server that sits in a DMZ (a system that has separate points of access to the "internal network" and the web) or something called a bastion host or something like a VPN through which you can add your remote computer directly to the "internal network" (where your database server will live). These are all topics you will need to research on your own to see which are within your means to deliver.
As to connecting... there are two things to pay attention to.
1) Where is your client relative to your server (on the same host or on a different host)
2) how TCP packets travel between those two points (which should include crossing through firewalls)
The first is important because an account like hol@localhost will be something completely different than another account like
hol@10.0.1.% . This is part of how MySQL provides different levels of logical access to clients that are in different physical proximities to the server. A "can't connect" has to do with physical network packet transfers. An "access denied" problem may be related to which account the server is attempting to match your login to and THAT will be based on where it sees your client coming FROM.
For more details, please review...
https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html
https://dev.mysql.com/doc/refman/8.0/en/problems-connecting.html
https://dev.mysql.com/doc/refman/8.0/en/connection-access.html
Yours,
--
Shawn Green
MySQL Product Support Manager, AMER region
Become certified in MySQL! Visit
https://www.mysql.com/certification/ for details.