Mysql8.0授权问题

The user specified as a definer ('root'@'%') does not exist 此种报错主要是针对访问视图文件引起的(没有权限)

 

1.先看下mysql是否设置了环境变量,如果没设置,就需要切换到mysql的bin目录下执行命令(我的已经设置过了)

用管理员身份打开widowns的命令提示符,就是win+R,cmd 那个

在此目录 C:\Program Files\MySQL\MySQL Server 8.0\bin  运行下面命令

 mysql -hlocalhost -uroot -p123456

这里的123456是你自己的mysql的 root的密码

2.给root用户添加权限

因为mysql8.0无法给用户授权 或 提示You are not allowed to create a user with GRANT、for the right syntax to use near 'identified by xxx'的问题

所以直接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

如下图

正确做法先创建用户

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'ukong';
Query OK, 0 rows affected (0.04 sec)

然后授权

mysql> grant all privileges on . to 'root'@'%';
Query OK, 0 rows affected (0.03 sec)
另外,如果远程连接的时候报错误,可以尝试修改密码加密插件:

mysql> alter user 'root'@'%' identified with mysql_native_password by 'ukong';

 

3.刷新权限

flush privileges;

 

这就ok了,我写的东西都是小白也能看懂的。我也是成长ing的小白。

写完本文后,在百度发现一篇文章

https://jingyan.baidu.com/article/1876c852c50e59c90b1376ed.html

这文章里的第13步说的很好

你可能感兴趣的:(MySQL)