Mysql-用户管理

创建用户

mysql8.0之后必须先建账号在授权

# 用户@'白名单' 例如:root@localhost表示可以在Localhost上使用root用户登录
# % 为通配符
#root@'10.0.0.0/255.255.255.0'
#root@'10.0.0.%'

#查
select user,host,authentication_string from user;

#建
create user jinwei@'%' identified by 'Mima+12345';

#删除
drop user jinwei@'%';

alter user root@'%' indentified by 'xinmima';

授权

#查看权限
show privileges;
#设置马上生效
flush privileges;

#查询用户权限
show grants for jinwei@'%';
#查询所有用户权限
select * from mys\G


#授权
grant  权限1,权限2,权限3  on  对象   to  用户   ;

#给管理员授权(mysql8中不能加with grant option)
grant  all  on  *.*   to  用户 with grant option  ;
#权限:
ALL                 :管理员
grant option        :特殊权限
ALL+grant option=超级管理员root

#特殊权限,让用户可以给别人授权
grant  权限1,权限2,权限3  on  对象   to  用户 with grant option  ;


#对象: 库,表
*.*                           :所有的库的表
tdb.*                         :给tds里的所有表
tbd.tb1                       :tdb中的tb1
tdb.tb1(col1,col2)            :给列授权

回收权限

mysql不能通过重复授权回收权限。

revoke  create on jinwei.tab1 from  jinwei@'%';

修改mysql root密码

#修改mysqld配置
vim /etc/my.cnf
#在mysqld中添加2行
skip-grant-tables   #跳过授权表
skip-networking     #跳过TCP/IP连接

#重启服务
systemctl restart mysqld
#随便一个密码登陆
mysql -uroot -p'ss'
#加载授权表
flush privileges;
#修改密码
alter user root@'%' identified by 'xinmima';
#修改成功后,退出,删掉配置中的2行,重启服务即可。
posted @ 2020-11-18 08:28  JinweiChang  阅读(95)  评论(0编辑  收藏  举报