今天从项目同事那拿到一个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语句挨个执行,最终效果如下,修改成功!

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

SELECT command denied to user ‘‘@‘%‘ for column ‘c_code‘ in table ‘sys_data_dictionary‘相关推荐

  1. 【mysql错误】SELECT command denied to user 'longfor_read'@'id地址' for table 'help_topic'

    2019独角兽企业重金招聘Python工程师标准>>> 在线错误提示: SELECT command denied to user 'longfor_read'@'id地址' for ...

  2. mysql 1143_ERROR 1143 (42000): SELECT command denied to user

    同事要update   MySQL  UAT 环境的基础数据表,发出了这样的授权申请语句.觉得没什么问题,也就给批准了. 你能看出这个授权语句有什么问题吗?e1534 这个用户已经存在,并且可以连接上 ...

  3. jdbc4.MySQLSyntaxErrorException: SELECT command denied to user '用户名'@'localhost' for table '表名'

    jdbc4.MySQLSyntaxErrorException: SELECT command denied to user '用户名'@'localhost' for table '表名' 异常信息 ...

  4. SQLSyntaxErrorException: SELECT command denied to user ‘XXXXX‘@‘xxxx‘ for table ‘XXXX‘ 异常解决

    项目场景: springboot项目集成了mybatis查询mysql数据库报Caused by: java.sql.SQLSyntaxErrorException: SELECT command d ...

  5. 解决mybatis的SELECT command denied to user 'root'@'192.168.1.47' for table 'user'的报错。mysql用户权限修改,表权限修改。

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'root'@'joc ...

  6. MySQL 1142 - SELECT command denied to user ‘xxx‘@‘xxx‘ for table ‘xxx‘问题解决

    问题描述: 1142 - SELECT command denied to user 'root'@'localhost' for table 't_user' 问题分析: 1.表名前面加了dbo., ...

  7. mysql中解决“SELECT command denied to user ‘nature‘@‘192.168.1.49‘ for table ‘user_variables_by_thread‘“

    前言 - - 原因 普通mysql用户nature对performance_schema数据库的user_variables_by_thread表没有select权限 解决 mysql> gra ...

  8. 1142 SELECT command denied to user ‘数据库‘@‘localhost‘ for table ‘表‘(没有授权)

    使用navicat授权 点击左上角 新建查询: use mysql; select * from user where user='数据库名'; 将红线部分改成 ' Y '即可,保存,重启mysql, ...

  9. 项目上线后,接口报错:SELECT command denied to user ‘用户名’ @ localhost‘ for table ‘ ‘

    项目上线后,有一个接口报错如下: 原因: 是因为换了另一个线上数据库,当前使用的用户操作权限不够 我这边直接使用了root用户 要是不方便直接使用root用户,可以到mysql库user表中更改该用户 ...

最新文章

  1. MySQL 大表优化方案
  2. asp.net mysql 读写分离_.NET Core实现分表分库、读写分离的通用 Repository功能
  3. linux作业控制三个,10个linux 作业控制的bash 脚本实例
  4. HDU - 4348To the moon——主席树+区间修改
  5. 软件集成策略故事连载----对项目的不利影响竟然这么大
  6. windows下修改host不生效的解决方法
  7. MySQL空闲会话_使用Oracle PROFILE控制会话空闲时间
  8. 分享一下把pdftk的合并pdf功能添加到TC(Totalcommander)
  9. java demo类_《java语言程序设计》初步学习——各种小Demo
  10. KM小鼠大脑海马区生理切片HE染色
  11. docker修改nginx容器主页内容信息【还能这样操作?】
  12. ROS2教程(入门级):记录和回播数据
  13. 正态分布以及推测统计简述
  14. 云队友丨当代攒钱青年现状:没变富,先「变负」
  15. 免费领取三个月苹果ARCADE订阅教程
  16. c# 第32节 类的继承
  17. 《中文核心期刊要目总览(2014年版)》——计算机、自动化类
  18. AspNetPager属性
  19. 关于comsol“LU因式分解时内存不足“的一些解决建议
  20. Launcher启动流程及初始化

热门文章

  1. VScommunity2019 0x00007FFCCA14B7EC (ucrtbased.dll) (Project1.exe 中)处有未经处理的异常: 将一个无效参数传递给了将无效参数视为严重错误
  2. 不学c语言能学mysql吗_学C语言难不难?以及简说数据库
  3. E2224和E5-2630v4的区别?
  4. ubuntu 火狐浏览器找不到服务器
  5. 面试题27-二叉树的镜像
  6. 〖Python 数据库开发实战 - Python与MySQL交互篇⑪〗- 项目实战- 完善新闻管理系统中轮询的交互判断
  7. 用户控制 键盘鼠标自定义 脚本
  8. 苹果三代耳机_【团品2】1.苹果原装数据线以及有线耳机 2.苹果蓝牙耳机
  9. 一步一步实现商城微信小程序(四)
  10. 最近碰到的上架苹果4.3问题分析