MySQLNonTransientConnectionException:无法创建与数据库服务器的连接.尝试重新连接3次.放弃 [英] MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up

查看:635
本文介绍了MySQLNonTransientConnectionException:无法创建与数据库服务器的连接.尝试重新连接3次.放弃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法连接到数据库.我认为有些地方我不知道,需要更改.我在这里有一些非常基本的代码:

I'm having trouble connecting to my database. I think there is a setting somewhere that I don't know about and needs to be changed. I have some really basic code here:

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();
    }
}

显然带有登录信息.并导致此错误:

Obviously with the login info. And it causes this error:

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个有关同一问题的不同文章,并尝试了他们的解决方案,但仍然无法正常工作.

I've looked through about 10 different posts about the same problem and tried their solutions and still couldn't get it to work.

推荐答案

当MySQL服务未运行并且您尝试连接到mysql数据库时,会发生此问题.

This problem occurs when the MySQL service is not running and you're trying to connect to the mysql database.

要在Windows中解决此问题,

To resolve this in Windows,

  • 开始>>键入服务"并打开它.

  • Start >> type 'services' and open it.

找到MySQL服务.可能名称为MySQLxx. xx为版本.
例如MySQL56,MySQL57等

Find the MySQL service. Probably with name MySQLxx. xx being the version.
eg. MySQL56, MySQL57 etc

启动服务,现在尝试连接到数据库.

Start the service and now try to connection to database.

这篇关于MySQLNonTransientConnectionException:无法创建与数据库服务器的连接.尝试重新连接3次.放弃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆