用户'User'@'localhost'拒绝MySQL访问(使用密码:YES)

时间:2016-03-08 05:05:12

标签: mysql database jsp netbeans

我在netbeans中为一个项目(java web应用程序)连接了一个MySQL数据库。我创建了具有正确登录详细信息的MySQL服务器,并创建了一个数据库。我将我的数据库连接到项目,但是当我运行应用程序时,它在浏览器中显示错误:

type Exception report

message Internal Server Error

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'User'@'localhost' (using password: YES)

root cause

java.sql.SQLException: Access denied for user 'User'@'localhost' (using password: YES)

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs. 

日志文件中的条目是:


java.sql.SQLException: Access denied for user 'User'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
    at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:822)
    at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at org.apache.jsp.Login_jsp.cn(Login_jsp.java:114)
    at org.apache.jsp.Login_jsp._jspService(Login_jsp.java:589)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) 

我在其他一些形式中提到的几种方式感到厌倦但没有使用。

2 个答案:

答案 0 :(得分:0)

您没有正确创建用户getLocation(); var rowId=timesheetGrid.uid(); var pos = timesheetGrid.getRowsNum(); timesheetGrid.addRow(rowId,["","","","<?php echo $ActiveWeek; ?>","","","","","","","","","","",Loc],0); //adds a new row with pre filled data timesheetGrid.selectCell(rowId,0,false,true,true); // Focus on the new row

答案 1 :(得分:0)

我找到了解决方案,当我使用sql语句获取授权权限时,我使用了

'user@%'
,因为它无效。正确的sql语句是:
GRANT ALL PRIVILEGES ON dbname.* TO 'User'@'localhost' IDENTIFIED BY 'Pass' WITH GRANT OPTION;