0

I have installed MySQL on my home server (Debian 9) and I can connect to the database with phpMyAdmin. But when I try to connect to the database with Java I get the following error:

Picture of the Error

My Code: (I replaced the real Password, IP and Username in this post with placeholders)

 Connection connection = DriverManager.getConnection("jdbc:mysql://ip:3306/users","username","****");
Finn
  • 1
  • Are you sure you are using the same ip with phpMyAdmin ? If the java software is running on the same computer as the – MTilsted Sep 02 '22 at 13:24
  • 2
    Please don't post pictures of errors, post it as code formatted text. In any case, the error means that MySQL is not running on port 3306 of ip, or that a firewall disallows access. – Mark Rotteveel Sep 02 '22 at 13:25
  • Is `ip` a non-loopback ip (e.g. 127.0.0.1)? If it's not on the local machine, MySQL very likely does not have permissions set for the user to connect from a non-local connection (this is the default). Rather than opening the database to external connections, I've found it's usually more secure to simply use ssh tunneling to get your sql connection up for development (`ssh -L 3306:localhost:3306 other-details`). If everything is configured correctly, then it's more than likely a firewall issue or otherwise. – Rogue Sep 02 '22 at 13:26

0 Answers0