用户'root'@'localhost'拒绝访问(使用密码:YES) [英] Access denied for User 'root'@'localhost' (using password: YES )

查看:345
本文介绍了用户'root'@'localhost'拒绝访问(使用密码:YES)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接我的本地MYSQL数据库,它与XAMP服务器一起安装。我创建了一个新用户,即NewUser,其密码为password。我给了这个用户所有的特权。

I would like to connect with my local MYSQL data base, which is installed along with XAMP server. I created a new User ie, " NewUser " and its password is "password". I given all PRIVILEGES to this user.

我使用用户root编写了连接数据库的代码(该用户没有密码)。
已连接。喜欢贝娄..

I write the code to connect with data base by using user "root" (No password for this user). Its connected . Like bellow..

return DriverManager.getConnection("jdbc:MySql://localhost/database_name","root","");

现在我编写了代码,以便由另一个用户连接相同的数据库,即NewUser及其密码password

Now I wrote the code to connect with same data base by another user ie, "NewUser" and its pasword "password"

return DriverManager.getConnection("jdbc:MySql://localhost/database_name","NewUser","password");

但未连接。
控制台中的错误是

but its not connected. The error in console is

java.sql.SQLException: Access denied for user 'NewUser'@'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.<init>(ConnectionImpl.java:822)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.GeneratedConstructorAccessor207.newInstance(Unknown Source)
    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:404)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
    at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:214)
    at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
    at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
    at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:73)
    at org.eclipse.datatools.enablement.internal.mysql.connection.JDBCMySQLConnectionFactory.createConnection(JDBCMySQLConnectionFactory.java:28)
    at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
    at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
    at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
    at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

我在向这个用户提供PRIVILEGES时给出主机类型,称为任何主机,即%。

I give the host type while providing PRIVILEGES to this user, as " any host" ie."%".

如果我将其更改为localhost或127.0.0.1它正在工作。

If I change this to " localhost " or "127.0.0.1" its working.

那么如何使用我的数据库anyhost对特定用户的特权如NewUser。

So How can i use my database with " anyhost " PRIVILEGES to the particular user like "NewUser" .

如果我在这里取得成功,那么我就成功了到客户端直播数据库..

If I got success here then I successes in connection to client live Data base..

感谢所有人,请让我从这一个出来......

Thanks to all and please let me out from this one.....

推荐答案

由于第一个指定的代码工作并且也基于报告的跟踪,我很确定问题出在数据库上,而不是代码语法。

Since the first specified code works and also based on the reported trace, i'm pretty sure the problem is on the database, not the code syntax.

根据Mysql版本,请尝试替代设置权限,而不指定基于 Mysql文档

Based on the Mysql version, please try as an alternative to set privileges without specifying the any host (%) as based on Mysql documentation,


简单形式user_name是user_name @'%'的同义词

The simple form user_name is a synonym for user_name@'%'

使用 FLUSH PRIVILEGES后立即刷新权限;

为了确保一切正确,还要运行
为NewUser显示资金; 并检查NewUser是否出现在具有相应权限的列表中。

Just to make sure everything is correct, also run a SHOW GRANTS FOR NewUser; and check if NewUser appears in the list with the corresponding permissions.

这篇关于用户'root'@'localhost'拒绝访问(使用密码:YES)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆