【问题标题】:JDBC MySQL connection - error reading communication packageJDBC MySQL连接——读取通信包报错
【发布时间】:2018-04-06 09:59:24
【问题描述】:

自从我从 Windows 转移到 Ubuntu 后,我无法再启动我的 Java Spring MVC 应用程序了。无法建立 MySQL 数据库连接。在迁移到 Ubuntu 之前,我的数据库连接没有任何问题(而且我没有更改代码)。

我的工作:

我的 Spring 应用使用以下连接字符串:

jdbc:mysql://localhost:3306/mydatabase?user=mydbuser&password=mypassword

错误是什么:

Spring 只告诉我没有数据库连接。但是当我查看数据库日志时,我可以看到以下错误:

Aborted connection 6 to db: 'mydatabase' user: 'mydbuser' host: 'localhost' (Got an error reading communication packets)

我已经尝试过的:

我可以使用mydbuser 通过 MySQL 控制台登录。数据库已存在,我的用户拥有所有权限。连接问题仅存在于 Spring 应用程序中。

我遵循了许多来自 stackoverflow 的建议,例如设置以下变量:

SET @@global.log_error_verbosity = 2;
SET @@global.max_connections = 400;
SET GLOBAL max_allowed_packet = 1024 * 1024 * 256;

你有什么想法我可以尝试或问题是什么?

【问题讨论】:

    标签: mysql spring-mvc


    【解决方案1】:

    检查 /etc/hosts 中是否有此行:

    127.0.0.1       localhost
    

    如果不添加,或者将连接字符串更改为:

    jdbc:mysql://127.0.0.1:3306/mydatabase?user=mydbuser&password=mypassword
    

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-04
      • 1970-01-01
      • 2017-07-31
      相关资源
      最近更新 更多