最近在调试mysql数据库时,发生以下错误
18:04:45,575 ERROR [STDERR] org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select productlib0_.servicelibvalueid as servicel1_7_, productlib0_.productid as productid7_, productlib0_.servicelibtypeid as servicel3_7_, productlib0_.servicelibid as servicel4_7_ from conferencemanagement.productlibtype productlib0_ where (productlib0_.productid=? )]; SQL state [HY000]; error code [1449]; There is no 'root'@'%' registered; nested exception is java.sql.SQLException: There is no 'root'@'%' registered
18:04:45,577 ERROR [STDERR] Caused by:
18:04:45,577 ERROR [STDERR] java.sql.SQLException: There is no 'root'@'%' registered
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
18:04:45,578 ERROR [STDERR] at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467)
排查错误,最后发现是数据库远程访问权限的问题,使用以下命令即可解决。
1. 登录mysql:mysql -uroot -ppasswd
2. 授权:GRANT ALL PRIVILEGES ON *.* TO'root'@'%'WITH GRANT OPTION //授权任何主机均有访问数据库的权限。
3. 重载权限信息:FLUSH PRIVILEGES //reload the grant tables
4. 退出:quit
另外,搜索到了其他修改方法,如下。
修改mysql数据库的user表
update user set host='%' where user = 'root';
select host, user from user;
--转自