java - Hibernate 无法连接到 debian 上的纯 MySQL 安装

标签 java mysql hibernate

我刚刚创建了一个新的虚拟机,它最初是完全干净的 -

我已经安装了 MySQL,设置了密码,现在我可以通过 PHPMyAdmin 访问它了。

我使用在我的其他服务器上运行的相同配置复制了我的 java 应用程序。但是它似乎很难连接到 MySQL 服务器。

您可以看到 MySQL 正在监听:

# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 localhost:mysql         *:*                     LISTEN      5307/mysqld   

在TOP中,我可以看到这两个进程:

5196 root      20   0  3956  632  508 S    0  0.0   0:00.00 mysqld_safe                                                                                                                                           
5307 mysql     20   0  167m  33m 6780 S    0  0.8   0:00.47 mysqld      

但是一旦我尝试运行该应用程序,我就会在 Hibernate 尝试连接时结束:

23:46:10,192  INFO org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl:127 - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/goout2?autoReconnect=true]
23:46:10,192  INFO org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl:132 - HHH000046: Connection properties: {user=goout2, writedelay=0, password=****, autocommit=true, shutdown=true, characterEncoding=UTF-8, charSet=UTF-8, release_mode=auto}
23:46:14,331  WARN org.hibernate.engine.jdbc.internal.JdbcServicesImpl:169 - HHH000342: Could not obtain connection to query metadata : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
23:46:14,340  INFO org.hibernate.dialect.Dialect:122 - HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
23:46:14,350  INFO org.hibernate.engine.jdbc.internal.LobCreatorBuilder:85 - HHH000422: Disabling contextual LOB creation as connection was null
23:46:14,362  INFO org.hibernate.engine.transaction.internal.TransactionFactoryInitiator:73 - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
23:46:14,367  INFO org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
23:46:14,944  INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:182 - HHH000228: Running hbm2ddl schema update
23:46:14,944  INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:193 - HHH000102: Fetching database metadata
23:46:18,949 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:201 - HHH000319: Could not get database metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

对于 C3P0,它是这样死的:

23:58:08,696  INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@2e902532 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@43a8e988 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> ahkzhz8n1trd1gkc8ious|37e8cf51, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@78875ab8 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> ahkzhz8n1trd1gkc8ious|20053644, jdbcUrl -> jdbc:mysql://localhost:5307/goout2?autoReconnect=true, properties -> {user=******, writedelay=0, password=******, autocommit=true, shutdown=true, characterEncoding=UTF-8, charSet=UTF-8, release_mode=auto} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> ahkzhz8n1trd1gkc8ious|347c8e1c, numHelperThreads -> 3 ]
23:58:28,694  WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector:608 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@457e133d -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
23:58:28,697  WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector:624 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@457e133d -- APPARENT DEADLOCK!!! Complete Status: 

显然 MySQL 不想接受来 self 的 Java 应用程序的连接,MySQL 日志也没有显示任何内容。我想,有一些我不知道的配置选项。

谢谢。

最佳答案

jdbc:mysql://localhost:5307/goout2?autoReconnect=true

5307不是标准的mysql端口。您是否尝试连接到端口 3306? 5307 似乎是 PID(进程 ID)而不是端口。

您也可以尝试通过 127.0.0.1 和/或您当前的 ip 进行连接。屏幕看起来您已启用 mysql 以监听该端口,但请确保它正在积极监听该端口。 telnet localhost 5307 mysqlserver 可以选择只监听本地套接字,确保它实际打开了一个端口。

关于java - Hibernate 无法连接到 debian 上的纯 MySQL 安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11041955/

相关文章:

mysql - 存储长二进制(原始数据)字符串

java - hibernate 循环外键

java - 我需要从列表字符串中迭代数据,并将以下 JSON 中的 "MemberOf "参数添加到另一个列表字符串中

java - 从字节数组 java 创建 BufferedImage

php - 将 SQL 转储到文件 : data with accent (italian) different charset

Java - 获取封闭实例

java - 在 Spring Boot 1.3.1.RELEASE 中升级到 Hibernate 5.0.6.Final 后嵌入式字段不起作用

java - Android 和 AppEngine 网络服务 : Json. .. RPC、REST... Protocol Buffer ?

java - 使用 AndEngine 限制声音播放

mysql - 错误 1093 (HY000) : You can't specify target table for update in FROM clause