尝试使用根问题访问数据库时拒绝访问

时间:2022-12-06 15:44:24

I have the following error:

我有以下错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'%' to database 'GUEST_BOOK'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    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.Util.getInstance(Util.java:386)

previously I have done:

以前我做过:

GRANT ALL PRIVILEGES ON GUEST_BOOK.* TO 'root@%' IDENTIFIED BY 'D7n()st1234' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

FLUSH PRIVILEGES;

not sure why it is still giving me that permission error? Any idea?

不确定为什么它仍然给我这个权限错误?任何想法?

1 个解决方案

#1


2  

'root@%' is different than 'root'@'%' in SQL terms

在SQL术语中,“root @%”与“root”@“%”不同

Essentially writing 'root@%' probably created an entry for a user called 'root@%' and not a user named root who would be accessing via any means (%)

基本上写'root @%'可能为一个名为'root @%'的用户创建了一个条目,而不是一个名为root的用户,他将通过任何方式访问(%)

Update your grant statement to read

更新您的grant语句以阅读

GRANT ALL PRIVILEGES ON GUEST_BOOK.* TO 'root'@'%' IDENTIFIED BY 'D7n()st1234' WITH GRANT OPTION;

#1


2  

'root@%' is different than 'root'@'%' in SQL terms

在SQL术语中,“root @%”与“root”@“%”不同

Essentially writing 'root@%' probably created an entry for a user called 'root@%' and not a user named root who would be accessing via any means (%)

基本上写'root @%'可能为一个名为'root @%'的用户创建了一个条目,而不是一个名为root的用户,他将通过任何方式访问(%)

Update your grant statement to read

更新您的grant语句以阅读

GRANT ALL PRIVILEGES ON GUEST_BOOK.* TO 'root'@'%' IDENTIFIED BY 'D7n()st1234' WITH GRANT OPTION;