Home  >  Article  >  Database  >  Access denied for user 'root'

Access denied for user 'root'

WBOY
WBOYOriginal
2016-06-07 15:42:581101browse

在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或%的记录

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn