对表'<表名>'的用户'<userid>'@'<my-pc-ip-address>'的SELECT命令被拒绝

时间:2019-06-25 10:11:58

标签: mysql spring-boot jpa spring-data-jpa mysql-workbench

当我使用邮递员从我的API获取响应时,出现此错误。

   java.sql.SQLSyntaxErrorException: SELECT command denied to user '<userid>'@'<my-pc-ip-address>' for table '<table-name>'
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.16.jar:8.0.16]

但是我可以在同一用户的Workbench中完美地使用SELECT语句。

application.properties

spring.datasource.url = jdbc:mysql://<database.ip>:3306/<database.schema>
spring.datasource.username = test
spring.datasource.password = test123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

我正在尝试使用root帐户,但出现此错误

java.sql.SQLSyntaxErrorException : Unknown database '<db_name>'

我可以用这个来解决这个问题

  1. 替换

@Table(表=“表名”)代替

@Table(表=“表名”,目录=“目录名”模式)

  1. 将其放置到application.properties

    spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

2 个答案:

答案 0 :(得分:0)

未授予用户“ test”访问数据库的权限。

您必须先授予它

请在手册中找到Grant命令 https://dev.mysql.com/doc/refman/8.0/en/grant.html

答案 1 :(得分:0)

就像Simon上面所说的那样,用户“ test”没有执行“ SELECT”操作的正确权限。

相关问题