The user specified as a definer (‘root‘@‘%‘) does not exist

在MySQL8.0版本中,尝试为不存在的用户'root'@'%'授予权限时遇到错误。由于8.0.11之后的版本移除了通过GRANT创建用户的特性,需要使用CREATE USER语句先创建用户,再进行权限分配。最终解决方案是:首先创建用户'root'@'%'并设置密码,然后授予所有权限,最后刷新权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The user specified as a definer (‘root’@’%’) does not exist

前提:

Mysql 8.0 版本 安装在window系统上。

描述:

最近一个活,运维新安装了mysql8.0在线上,程序部署上去后各种问题。这套程序有使用视图,代码代码中运行提示

The user specified as a definer (‘root’@’%’) does not exist 错误。

通过Navicat查看,只有默认的一个root用户
系统默认用户

网上查了下相关问题的处理方法,基本都是这句

grant all privileges on *.* to root@"%" identified by ".";

实际运行就会出错

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by "."' at line 1

问题原因:

mysql8.0 以后这句的用法不一样了。

查询资料后,发现是版本的问题,8.0.11版本之后移除了grant 语句添加用户的功能,也就是说grant…只能适用于已存在的账户,不能通过 grant… 来添加账号了。

Using GRANT to modify account properties other than privilege assignments. This includes

authentication, SSL, and resource-limit properties. Instead, establish such properties at account-creation

time with CREATE USER or modify them afterward with ALTER USER.

最后的解决语句:

create user 'root'@'%' identified by 'USM@2020';
grant all privileges on *.* to 'root'@'%';
flush privileges;

参考原贴

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值