项目场景:
安装调试MariaDB
问题描述:
在修改MariaDB中 mysql.user 表时,发生如下错误
View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
原因分析:
根据SQL响应异常来看,第一反应应该是表/字段/方法异常或者是权限异常,但是检查了用户权限与数据库结构后,排除了这两个问题
细看之下,发现了这个提示:`of view lack rights to use them`,这里面提到了`view`也就是视图,是不是说明,mysql.user不是一张表?于是google之
MariaDB官方资料说,mysql.user从10.4版本开始,不再是一张表而是一个视图
In MariaDB 10.4 and later, the mysql.global_priv table has replaced the
mysql.usertable, andmysql.usershould be considered obsolete. It is now a view intomysql.global_privcreated for compatibility with older applications and monitoring scripts. New tools are supposed to useINFORMATION_SCHEMAtables. From MariaDB 10.4.13, the dedicatedmariadb.sysuser is created as the definer of the view. Previously,rootwas the definer, which resulted in privilege problems when this username was changed (MDEV-19650).
P.s 参考https://mariadb.com/kb/en/mysqluser-table/
https://mariadb.com/kb/en/mysqluser-table/
并且提供了一个新表mysql.global_priv来替代mysql.user,而且提供了一个新的命令:ALERT USER,所以,解决方案就来了
解决方案:
1. 编辑mysql.global_priv表:
UPDATE mysql.global_priv SET Host='%' WHERE User='root';2. 使用 `ALTER USER` 命令:
有待研究
对了,别忘了刷新一下权限:
flush privileges;