简体   繁体   English

无法创建与数据库服务器的连接。 强、jdbc、mysql数据库

[英]Could not create connection to database server. Strong, jdbc, mysql database

My mySQL server is hosted on a ubuntu server vm @ 10.0.0.200, with an ssh port at 3333. MySQL 服务器托管在 ubuntu 服务器 vm @ 10.0.0.200 上,ssh 端口位于 3333。

Attempting to start the spring boot app gives me this error:尝试启动 spring boot 应用程序给了我这个错误:

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

My application.properties looks like this:我的 application.properties 看起来像这样:

spring.datasource.url = jdbc:mysql://10.0.0.200:3306/test?useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true
spring.datasource.username = boss
spring.datasource.password = StrongPass123!
spring.jpa.show-sql= true
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5Dialect

I was thinking maybe I need to specify the ssh port for my vm ans tried:我在想也许我需要为我的虚拟机指定 ssh 端口并尝试过:

spring.datasource.url = jdbc:mysql://{10.0.0.200:3333}:3306/test?useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true

And got the same error.并得到同样的错误。 I tried setting the bind address of mysql in my.cnf to my vm's IP(localhost).我尝试将my.cnf中mysql的绑定地址设置为我的vm的IP(localhost)。 to no avail.无济于事。

I am sure the credentials are correct, But have yet to get spring to start up right.我确信凭据是正确的,但还没有让春天正确启动。

Error trace:错误跟踪:

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:898) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448) ~[mysql-connector-java-8.0.29.jar:8.0.29]  
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.29.jar:8.0.29]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]   
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar:na]
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar:na]
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar:na]        
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 
~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 
~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:173) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]

In order to solve SQLNonTransientConnectionException error, I would first suggest using a strategy from an older stackoverflow post found here: SQLNonTransientConnectionException: No current connection, in my application while interacting with Derby database为了解决 SQLNonTransientConnectionException 错误,我首先建议使用此处找到的旧 stackoverflow 帖子中的策略: SQLNonTransientConnectionException: No current connection, in my application while intering with Derby database

If that does not work, then I would attempt to model your code in application.properties code after this:如果这不起作用,那么我会在此之后尝试在 application.properties 代码中对您的代码进行建模:

 spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example spring.datasource.username=springuser spring.datasource.password=ThePassword spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver #spring.jpa.show-sql: true

Which I found the in the application.properties properties section of https://spring.io/guides/gs/accessing-data-mysql/ .我在https://spring.io/guides/gs/accessing-data-mysql/的 application.properties 属性部分找到了它。 So that information is straight from the source.因此,该信息直接来自源头。 If you can get it working with the structure from Springs standard example, then you can add the other properties one by one, build and re-run the code again prior to testing the connection.如果您可以使用 Springs 标准示例中的结构,则可以一一添加其他属性,在测试连接之前再次构建并重新运行代码。

Sometimes completely shutting down your IDE and then re-opening it helps as well.有时完全关闭您的 IDE,然后重新打开它也会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法创建到 MySQL 数据库服务器的 JDBC 连接 - Could not create JDBC connection to MySQL database server Problem connect Android Studio-MySQL using JDBC (Error: java.sql.SQLNonTransientConnectionException: Could not create connection to database server.) - Problem connect Android Studio-MySQL using JDBC (Error : java.sql.SQLNonTransientConnectionException: Could not create connection to database server.) MySql 与 azkaban 连接时出现错误“无法创建 PoolableConnectionFactory(无法创建与数据库服务器的连接。)”? - MySql error “Cannot create PoolableConnectionFactory (Could not create connection to database server.)” while connecting with azkaban? jdbc:无法创建到数据库服务器的连接 - jdbc: Could not create connection to database server SQLException: 无法创建到数据库服务器的连接。 SQLState: 08001 - SQLException: Could not create connection to database server. SQLState: 08001 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接 - com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server 无法创建与数据库服务器MySQL 8.0的连接 - Could not create connection to database server, MySQL 8.0 无法建立与数据库服务器的连接。 尝试重新连接3次。 放弃 - Could not create connection to database server. Attempted reconnect 3 times. Giving up 08001] 无法创建到数据库服务器的连接。 索引 5 超出长度 5 的范围 - SQL 错误 - 08001] Could not create connection to database server. Index 5 out of bounds for length 5 - SQL error MySQLNonTransientConnectionException 无法创建与数据库服务器的连接。 引起:java.lang.NullPointerException - MySQLNonTransientConnectionException Could not create connection to database server. Caused by: java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM