I have a problem with connection to my mySQL databases (via IntelliJ Ulitimate) – most probably problem with connection between windows and wsl2 (Ubuntu-20.04 distribution).
Problem is quiet simple – always after couple of minutes (15 – 30, sometimes more) of working with mySQL database onIntelliJ and some queries done my connection with database is broken (usually as a result of a simple query). Message appears: “java.net.ConnectException: Connection refused: connect.”
When I test connection (via localhost) the message is:
“[08S01] Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
java.net.ConnectException: Connection refused: connect.”
Actually one thing which helps in 100% is restarting my laptop. Then, after starting MySQL everything runs great for next 20-30 minutes, until the same error of connection emerges.
Second solution is: terminating WSL (eg on PowerShell), restarting IntelliJ, starting MySQL - it works... but not always (ca 8/10 attempts) and since I must restarting IntelliJ is not very much conmfortable
I tried and didn't work:
simple restarting IntelliJ (also after stopping MySQL via terminal and starting again)
terminating WSL and then again starting a terminated WSL distro (but without restarting IntelliJ)
turning off windows defender firewall (and whole windows defender)
I also tried to connect not through localhost but through ip – and that doesn’t work at all (it doesn’t work even in this time when MySQL connection through localhost is OK (= eg. after restarting my computer) )
creating new user with all privilages
My Windows is updated, ping works.
EDIT: At the same time, everything works well, when I use mySQL from terminal command line (connection to database is OK).
As a beginner in Java I would be very thankful for any advice.