Phpstorm数据库:java.sql.SQLException:通信链接失败

时间:2014-12-06 18:04:35

标签: mysql database jdbc intellij-idea phpstorm

我正在使用JetBrains PHPStorm在网站上工作。 我使用默认设置创建了一个数据库,当我尝试测试连接或连接到数据库时,会弹出以下错误:

  

与db_IHM的连接失败   java.sql.SQLException:通信链接失败

     

成功发送到服务器的最后一个数据包是0毫秒   前。驱动程序未收到来自服务器的任何数据包。在   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)   在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)   在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   在java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  在com.mysql.jdbc.Util.handleNewInstance(Util.java:377)at   com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036)   在com.mysql.jdbc.MysqlIO。(MysqlIO.java:338)at   com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
  在   com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)   在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)   在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:790)at   com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:44)at   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)   在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)   在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   在java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  在com.mysql.jdbc.Util.handleNewInstance(Util.java:377)at   com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
  在   com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)   在   com.intellij.persistence.jdbc.impl.RemoteDriverImpl.connect(RemoteDriverImpl.java:27)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)   在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:606)at   sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
  在sun.rmi.transport.Transport $ 1.run(Transport.java:177)at   sun.rmi.transport.Transport $ 1.run(Transport.java:174)at   java.security.AccessController.doPrivileged(Native Method)at   sun.rmi.transport.Transport.serviceCall(Transport.java:173)at   sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)   在   sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run0(TCPTransport.java:811)   在   sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run(TCPTransport.java:670)   在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   在java.lang.Thread.run(Thread.java:724)at   sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)   在   sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)   在sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)at   java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)   在   java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)   在com.sun.proxy。$ Proxy86.connect(未知来源)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)   在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:606)at   com.intellij.execution.rmi.RemoteUtil $ RemoteInvocationHandler.invoke(RemoteUtil.java:214)   在com.sun.proxy。$ Proxy87.connect(未知来源)at   com.intellij.javaee.module.view.dataSource.LocalDataSource.getConnection(LocalDataSource.java:241)   在   com.intellij.javaee.module.view.dataSource.LocalDataSource.getConnection(LocalDataSource.java:217)   在   com.intellij.javaee.dataSource.DataSource.getConnection(DataSource.java:319)   在   com.intellij.javaee.dataSource.DataSource.performJdbcOperation(DataSource.java:363)   在   com.intellij.javaee.dataSource.AbstractDataSource.refreshMetaData(AbstractDataSource.java:32)   在   com.intellij.javaee.module.view.dataSource.DataSourceUiUtil $ 2.run(DataSourceUiUtil.java:177)   在   com.intellij.openapi.progress.impl.ProgressManagerImpl $ TaskRunnable.run(ProgressManagerImpl.java:464)   在   com.intellij.openapi.progress.impl.ProgressManagerImpl $ 2.run(ProgressManagerImpl.java:178)   在   com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)   在   com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)   在   com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)   在   com.intellij.openapi.progress.impl.ProgressManagerImpl $ 8.run(ProgressManagerImpl.java:373)   在   com.intellij.openapi.application.impl.ApplicationImpl $ 8.run(ApplicationImpl.java:420)   在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)   在java.util.concurrent.FutureTask.run(FutureTask.java:262)at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   在java.lang.Thread.run(Thread.java:724)at   com.intellij.openapi.application.impl.ApplicationImpl $ 1 $ 1.run(ApplicationImpl.java:150)   引起:java.net.ConnectException:连接被拒绝:连接在   java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)at   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)   在   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)   在   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)   在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)at   java.net.Socket.connect(Socket.java:579)at   com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213)   在com.mysql.jdbc.MysqlIO。(MysqlIO.java:297)at   com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
  在   com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)   在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)   在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:790)at   com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:44)at   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)   在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)   在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   在java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  在com.mysql.jdbc.Util.handleNewInstance(Util.java:377)at   com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
  在   com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)   在   com.intellij.persistence.jdbc.impl.RemoteDriverImpl.connect(RemoteDriverImpl.java:27)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)   在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   在java.lang.reflect.Method.invoke(Method.java:606)at   sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
  在sun.rmi.transport.Transport $ 1.run(Transport.java:177)at   sun.rmi.transport.Transport $ 1.run(Transport.java:174)at   java.security.AccessController.doPrivileged(Native Method)at   sun.rmi.transport.Transport.serviceCall(Transport.java:173)at   sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)   在   sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run0(TCPTransport.java:811)   在   sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run(TCPTransport.java:670)   在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)   在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)   在java.lang.Thread.run(Thread.java:724)

3 个答案:

答案 0 :(得分:7)

我遇到了这个问题,我需要启用"允许网络访问mysql"它的工作原理。 configuration settings on mamp pro

答案 1 :(得分:5)

在MAMP上与PHPStorm存在同样的问题。检查安装了MySQL的localhost中的端口。它是8889而不是默认3306.更新端口为我解决了问题。

答案 2 :(得分:2)

如果您更新了端口号,则会解决此问题。所以我认为如果您知道找到安装mysql的端口号的步骤会有所帮助。

在sql查询后的mysql客户端类型中:

SHOW GLOBAL VARIABLES LIKE 'PORT';

或使用此stackoverflow链接

How to test which port MySQL is running on and whether it can be connected to?