2015-11-25 10:51:54.0|分类: mysql|浏览量: 6426
某天升级mysql数据库程序发现报错The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server., 发现登陆用户、密码正确,连接池正确,mysql运行正确。最后把localhost修改成127.0.0.1即jdbc:mysql://127.0.0.1:3306/cookqq 为什么呢???看看下面分析 研究过程(1)jdbc:mysql://127.0.0.1:3306/cookqq 数据库驱动连接地址,重要的信息是ip+端口号 (2)3306端口号没有问题 (3)数据库cookqq也存在 (4)那就是location这个地址,mysql没有识别,为什么没有识别呢 (5)127.0.0.1/8整个都是环回地址,用来测试本机的TCP/IP协议栈,发往这段A类地址数据包不会出网卡,网络设备不会对其做路由。 (6)localhost=127.0.0.1,只不过localhost是域名,127.0.0.1是IP地址。一般系统都默认将localhost映射到127.0.0.1地址上 在 Windows 中,这个域名是预定义的,从 hosts 文件中可以看出: # localhost name resolution is handled within DNS itself.# 127.0.0.1 localhost#::1 localhost而在 Linux 中,其定义位于 /etc/hosts 中: 127.0.0.1 localhost (7)原来是这个原因。也就是localhost只是一个普通域名,如果你映射到127.0.0.1,就能找到本机 如果你去掉localhost这个域名,或者把localhost映射到其他的地址上,mysql首先获取localhost,然后拿localhost去hosts文件去找相应的ip,找到就正确返回,找不到就报错 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:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 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:348) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2391) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2428) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2213) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) |