Exception in thread “main” com.mysql.exceptions.jdbc4.
CommunicationsException:
Communication link failure. The last packet sent successfully to the server was 0 milliseconds ago.
No packet has been received by the driver from the server.
I also got this error once because I didn't start my server before running this program.
I ran my program without starting the MySQL server.
So, I did cross-checking and after starting the MySQL server, everything was fine.
You can also try another approach where you can do replacement of Localhost to your IP address:
Mysql -u username -p
- You will be asked for the password associated with the username. Does the MySQL client connect after providing the correct password?
- You might have to start MySQL from the preferences. If not, you can also set it to run at the startup.