日期:2014-05-17  浏览次数:20965 次

访问mysql数据库问题
我今天用navicat for mysql 时改表里的字段名时老出错,昨天也遇到过,我把管理用户里的权限全勾上后,就可以改了,今天却不行,我不小心吧localhost用户删了,这个用户是我电脑上的,还是navicat 上,重装navicat 也没这个用户。后面访问数据库报错
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (null, message from server: "Host 'localhost' is not allowed to connect to this MySQL server")
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.apache.commons.dbutils.QueryRunner.prepareConnection(QueryRunner.java:337)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:485)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:507)
at com.v512.jobedu.blog.DBOperator.getCategoryList(DBOperator.java:179)
at com.v512.jobedu.blog.BlogServlet.doPost(BlogServlet.java:38)
at com.v512.jobedu.blog.BlogServlet.doGet(BlogServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: null, message from server: "Host 'localhost' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1096)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2048)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
... 21 more

------解决方案--------------------
在用户权限里,没有localhost的设置,也就是本机不能访问数据库。

在navigte的用户管理里面,把这个用户加上吧,记得主机填写localhost

如果连接不上,可以备份磁盘目录的除了system的目录,然后重装数据库,然后还原备份就行了