问题
登录不上,查询发现root用户消失了
select user,plugin from user ;
解决
1、跳过验证
找到 /etc/my.cnf在mysqld后添加skip-grant-tables
重启
systemctl restart mysqld
查看状态
systemctl statusmysqld
2、登录
输入mysql直接登录
3、查询用户
select user,plugin from user ;
发现没有root
4、新增用户
create user 'test1'@'%' identified by '‘密码';
参数说明:
localhost : 作用本地
% : 任意ip都能连接 也可以指定ip连接
flush privileges;刷新权限
修改密码
Alter user 'test1'@'localhost' identified by '新密码';
flush privileges;
授权
grant all privileges on *.* to 'test1'@'localhost' with grant option;
with gran option表⽰该⽤户可给其它⽤户赋予权限,但不可能超过该⽤户已有的权限 ⽐如a⽤户有select,insert权限,也可给其它⽤户赋权,但它不可能给其它⽤户赋delete权限,除了select,insert以外的都不能 这句话可加可不加,视情况⽽定。
all privileges 可换成select,update,insert,delete,drop,create等操作 如:grant select,insert,update,delete on
*.* to 'test1'@'localhost'; 第⼀个*表⽰通配数据库,可指定新建⽤户只可操作的数据库 如:grant all privileges on 数据库.* to 'test1'@'localhost'; 第⼆个*表⽰通配表,可指定新建⽤户只可操作的数据库下的某个表 如:grant all privileges on 数据库.指定表名 to 'test1'@'localhost';
查看⽤户授权信息
show grants for 'test1'@'localhost';
权限拓展操作:
撤销权限:
revoke all privileges on *.* from 'test1'@'localhost';
⽤户有什么权限就撤什么权限
删除⽤户:
drop user 'test1'@'localhost';
5、还原配置文件并重启
参见第一步