首页  >  文章  >  数据库  >  Access denied for user 'root'

Access denied for user 'root'

WBOY
WBOY原创
2016-06-07 15:42:581167浏览

在java项目中使用连接串设为 localhost 时报以下错误,但在服务器中使用mysql -u root却可以登录 2014-08-29 09:05:29,181 WARN com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1841) - com.mchange.v2.resourcepoo

在java项目中使用连接串设为 localhost 时报以下错误,但在服务器中使用mysql -u root却可以登录

2014-08-29 09:05:29,181 WARN  com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1841) - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@67618412 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (10). Last acquisition attempt exception: 

java.sql.SQLException: Access denied for user 'root'@'127.0.0.1' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)

原因:

mysql.user中有多条root用户的权限记录,其中有些绑定了ip或域名(host字段)。

解决方法:

user中有多条root记录时,mysql会优先判断是否使用了绑定的ip,所以将localhost设置成对应的Ip 就可以,也可以把user表中绑定固定Ip的记录删除,只保留host字段为localhost或%的记录

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn