java.sql.SQLSyntaxErrorException: 指定的键太长并且连接被拒绝同时发生

huangapple go评论73阅读模式
英文:

java.sql.SQLSyntaxErrorException: Specified key was too long and connection refused simultaneously happening

问题

在我的Java + Gradle Spring后端中,当在本地测试并尝试连接到本地的MySQL数据库时,我遇到了一个指定的密钥过长的错误,我怀疑这与编码在正常设置下填充数据库有关(据我所知,某些编码占用更多字节,会溢出默认设置)。但是,它还声称连接被拒绝,这意味着端口未监听。我认为这很奇怪,因为telnet localhost 1433返回连接成功。我不太确定如何调试这个问题,也不知道这两个问题如何相关,有人可以指点我一下吗?谢谢!

编辑:这是我的application.properties文件

server.port=8443
server.ssl.key-store-password=${Password}
server.ssl.key-store=classpath:baeldung.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=PKCS12

spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:1433/${databasename}?useSSL=true&serverTimezone=UTC
spring.datasource.username=${username}
spring.datasource.password={$dbpassword}
英文:

In my java+gradle spring backend, while testing with localhost and attempting to connect to a mysql DB on localhost, I'm getting an error that specified key was too long, which I suspect has something to do with encoding overfilling the DB in it's regular setting (to my knowledge, some encodings take up more bytes which overflow the default setting). But, it's also claiming that the connection is refused which implies that the port isn't listening. I thought this was odd because a telnet localhost 1433 returns that the connection succeeded. I'm not particularly sure how to debug the issue nor how these 2 relate, can someone point me in the right direction? Thanks!

Edit: Here's my application.properties

server.port=8443
server.ssl.key-store-password=${Password}
server.ssl.key-store=classpath:baeldung.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=PKCS12

spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:1433/${databasename}?useSSL=true&serverTimezone=UTC
spring.datasource.username=${username}
spring.datasource.password={$dbpassword}

答案1

得分: 1

这似乎与用于创建数据库的引擎有关(与正在运行的 SQL 服务器的引擎不一致,后者使用的是 innoDB)。在 application.properties 中添加以下行:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect

解决了这个问题,并使其使用了正确的引擎。现在可以正常连接了。

英文:

Apparently, it had something to do with the engine that was being used to create the db (inconsistency with that of the running SQL server, which was using innoDB). This line:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect

in application.properties fixed it and got it to use the right engine. It can connect fine now.

huangapple
  • 本文由 发表于 2020年8月8日 01:56:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63306991.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定