我无法连接到我的数据库。我认为某个地方有一个我不知道并且需要更改的设置。我这里有一些非常基本的代码:
public static void main(String[] args)
{
try
{
Connection con = DriverManager.getConnection("jdbc:mysql://IP:3306/TABLENAME?autoReconnect=true","USERNAME", "PASSWORD");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
显然有登录信息。它会导致此错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
Caused by: java.net.ConnectException: Connection refused
我浏览了大约 10 个关于同一问题的不同帖子并尝试了他们的解决方案,但仍然无法解决问题。
原文由 Diet Cookiez 发布,翻译遵循 CC BY-SA 4.0 许可协议
当 MySQL 服务未运行并且您尝试连接到 mysql 数据库时,会出现此问题。
要在 Windows 中解决此问题,
开始 >> 输入“服务”并打开它。
找到 MySQL 服务。可能名称为 MySQLxx。 xx 是版本。
例如。 MySQL56、MySQL57 等