SELECT command denied to user ‘‘@‘%‘ for column ‘c_code‘ in table ‘sys_data_dictionary‘

1 篇文章 0 订阅

今天从项目同事那拿到一个sql脚本,导入数据库后,微服务一直启动报错,数据库方面用的JPA,报错信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Error accessing tables metadata
...
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.SQLGrammarException: Error accessing tables metadata
...
Caused by: org.hibernate.exception.SQLGrammarException: Error accessing tables metadata
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user ''@'%' for column 'c_code' in table 'sys_data_dictionary'
...

在网上搜了一圈,也没有找到特别好的解释 和 解决方案,于是觉得有必要记录一下。

错误原因


主要由于 **数据库视图定义 影响到 访问权限* *,导入的sql脚本的 DEFINER 为 root@% ,目测应该是同事 那边的 视图定义者名称;而我本地数据库的 DEFINER 均为 mysql.sys@localhost,由于在本地找不到 root@%,所以影响到数据库表字段的访问权限。
执行如下sql能看到 当前数据库视图定义:
# 查看mysql的视图定义者
select TABLE_SCHEMA,TABLE_NAME,DEFINER from information_schema.VIEWS;

在这里插入图片描述

解决方案


  1. 执行生成alter VIEW的SQL

其中 root@% 为原视图定义者,mysql.sys@localhost 为目标视图定义者

select concat("alter DEFINER='mysql.sys'@'localhost' SQL SECURITY DEFINER VIEW ",TABLE_SCHEMA,".",TABLE_NAME," as ",VIEW_DEFINITION,";") from information_schema.VIEWS where DEFINER = 'root@%';

执行效果如下:
在这里插入图片描述

  1. 执行alter VIEW的SQL,以达到修改DEFINER的目的

每一条alter语句挨个执行,最终效果如下,修改成功!
在这里插入图片描述

此时再去启动微服务,显示成功 ~

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值