我正在默认 3306 端口上从 Linux 连接到 MySQL(5.1.6)数据库,一切都很好:
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/wpdb" />
<property name="username" value="root" />
<property name="password" value="" />
现在,我进入 /etc/mysql/my.cnf 并将默认端口更改为 3307([client] 和 [mysqld])重新启动 MySQL,调整休眠连接 url:
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3307/wpdb" />
<property name="username" value="root" />
<property name="password" value="" />
并重新启动jboss。这次我无法再连接:
08:22:05,276 WARN [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-13) SQL Error: 0, SQLState: 08S01
08:22:05,276 ERROR [org.hibernate.util.JDBCExceptionReporter] (MSC service thread 1-13) Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
08:22:05,277 WARN [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-13) Could not obtain connection to query metadata: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_26]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_26]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_26]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_26]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2209) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) [mysql-connector-java-5.1.9.jar:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_26]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_26]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_26]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_26]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284) [mysql-connector-java-5.1.9.jar:]
at java.sql.DriverManager.getConnection(DriverManager.java:582) [rt.jar:1.6.0_26]
at java.sql.DriverManager.getConnection(DriverManager.java:154) [rt.jar:1.6.0_26]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173) [spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164) [spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149) [spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119) [spring-jdbc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) [spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:114) [hibernate-core-3.5.1-Final.jar:3.5.1-Final]
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163) [hibernate-core-3.5.1-Final.jar:3.5.1-Final]
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159) [hibernate-core-3.5.1-Final.jar:3.5.1-Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383) [hibernate-core-3.5.1-Final.jar:3.5.1-Final]
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954) [hibernate-annotations-3.5.1-Final.jar:3.5.1-Final]
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860) [spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779) [spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) [spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:400) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:103) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728) [spring-context-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449) [spring-context-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_26]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_26]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_26]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_26]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343) [mysql-connector-java-5.1.9.jar:]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2132) [mysql-connector-java-5.1.9.jar:]
... 59 more
Caused by: java.net.ConnectException: Connection refused
知道mysql拒绝连接的原因是什么吗?没有更改其他配置..但是 MySQL 默认端口。也没有防火墙启动和运行。
感谢您的任何建议。