2012-06-14 21 views
1

我剛剛創建一個新的虛擬機,這是最初完全乾淨的 - 我已經安裝了MySQL休眠無法連接到純MySQL安裝Debian的

,設置密碼,現在我可以通過訪問它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... [email protected] [ connectionPoolDataSource -> [email protected] [ 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 -> [email protected] [ 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[email protected]457e133d -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks! 
23:58:28,697 WARN com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector:624 - com[email protected]457e133d -- APPARENT DEADLOCK!!! Complete Status: 

顯然,MySQL並不想接受來自我的Java應用程序的連接,MySQL日誌不顯示任何內容。我想,有一些我不知道的配置選項。

謝謝。

回答

2

JDBC:MySQL的://本地主機:5307/goout2 autoReconnect的=真

5307是不標準的MySQL端口?。你有沒有嘗試連接到端口3306? 5307似乎是PID(進程ID)而不是端口。

您也可以嘗試通過127.0.0.1和/或您當前的IP進行連接。屏幕看起來像你已經啓用mysql來監聽那個端口,但是確保它正在主動監聽那個端口。 telnet localhost 5307 mysqlserver有一個選項只能監聽本地套接字,確保其實際打開一個端口。

+0

對不起,5307被遺忘的港口,它實際上不存在了。將嘗試與127.0.0.1 –

+1

@Vojtěch更新了帖子。 5307可能只是一個PID而不是一個港口。 –

+0

/etc/hosts丟失了本地主機 - 127.0.0.1沒有辦法。謝謝! –