我正在尝试将
PHPStorm连接到我的网站服务器上的数据库,该数据库托管在BlueHost的Linux机器上.
为此,我单击屏幕右侧的“数据源”选项卡,图标,然后弹出“数据源源数据源属性”对话框.我输入了源的名称,将Data Source Level设置为Project.然后下载了MysqL Connector / J-5.1.18 JDBC驱动程序文件.这为JDBC驱动程序类填充了大约6-7个类,包括com.MysqL.jdbc.Driver.
我相信我遇到的问题是数据库URL.它要求一个我不熟悉的jdbc:// url.我使用了示例格式jdbc:MysqL:// [host] [,failoverhost …] [:port] / [database]以及我的用户名和密码.
对于主机,我尝试过localhost,以及MysqL服务器盒的名称###.bluehost.com.端口3306,数据库的名称非常简单.
我在尝试测试连接时收到此错误…
Connection to Data Source Failed java.sql.sqlException: 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) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.MysqL.jdbc.Util.handleNewInstance(Util.java:411) at com.MysqL.jdbc.sqlError.createCommunicationsException(sqlError.java:1116) at com.MysqL.jdbc.MysqLIO.<init>(MysqLIO.java:344) at com.MysqL.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332) at com.MysqL.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369) at com.MysqL.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153) at com.MysqL.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792) at com.MysqL.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.MysqL.jdbc.Util.handleNewInstance(Util.java:411) at com.MysqL.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381) at com.MysqL.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305) in RemoteDriverImpl.connect(RemoteDriverImpl.java:27) in LocalDataSource.getConnection(LocalDataSource.java:105)
这个问题与其他问题的主要区别在于,这不是连接到wamp或mamp堆栈,而是连接到远程数据库.
解决方法
如果您使用Mamp并且遇到此问题,请打开MAMP并取消选中“仅允许本地访问”.