处理新建用户没权限操作数据库,版本不同,命令不一样,以下为8.0.25版本
1、进入到数据库命令行模式
mysql -u root -p
2、创建用户
create user 'test'@'%' identified by 'password';
3、赋予权限
with grant option这个选项表示该用户可以将自己拥有的权限授权给别人
指定数据库给tes用户授权
grant all privileges on 想授权的数据库.* to 'test'@'%' with grant option;
#给tset用户授予所有数据库权限
grant all privileges on *.* to 'test'@'%' with grant option;
如果权限要分的细一点all 换成 select,delete,update,create,drop,需要什么权限给什么权限
有些版本'%'不包括localhost,要单独对@'localhost'进行赋值
grant select,insert,update,delete on *.* to test@"localhost" Identified by "testpassword";
4、刷新配置
flush privileges;
5、修改mysql root账号密码
update mysql.user set authentication_string='新密码' where user='root';