4.2授权和取消

MySQL用户管理

相关数据库和表

元数据数据库:mysql

系统授权表

db,存储授权用户对数据库的访问权限

host,

user,存储授权用户的访问权限

columns_priv,存储用户对字段的访问权限

tables_priv,存储用户对表的访问权限

procs_priv,proxiea_priv

用户账号:'USERNAME'@'HOST'

如何对字段设置权限:

GRANT ALL (col1, col2, col3) ON mydb.mytable TO 'user'@'host';
#mydb.mytable 表示mysql数据库下的mytable表, col1, col2, col3表示mytable表中的列名
1、利用 MySQL proxies_priv(模拟角色)实现类似用户组管理
2、角色(Role)可以用来批量管理用户,同一个角色下的用户,拥有相同的权限。
3、MySQL5.7.X以后可以模拟角色(Role)的功能,通过mysql.proxies_priv模拟实现
创建用户
create user 'username'@'host' [identified by 'password'];
用户重命名
rename user old_user_name to new_user_name;
删除用户
drop user 'username'@'host';
修改密码
set password for 'user'@'host' =PASSWORD('password');
uopdate mysql.user set authentication_string=password('123456') where user='root';(此方法需执行下面指令才生效)
flush privileges;
破解root密码
1、停止mysql服务程序:service mysqld stop
2、跳过授权表启动mysql服务程序
  skip-grant-tables------->写入到/etc/my.cnf配置文件
  vim /etc/my.cnf
  [mysqld]
  skip-grant-tables
3、重设root密码:update mysql.user set authentication_string=password('123456') where user='root';
4、以正常方式重启mysql服务程序:注释skip-grant-tables并重新启动
权限管理
权限类别
  管理类
  程序类
  数据库级别
  表级别
  字段级别
管理类
create user
file
super
show database
reload
shutdown
replication slave
replication client
lock tables
process
create temporary tables
程序类:针对function\procedure\trigger
create
alter
drop
excute
库和表级别:针对datebase\table
alter
create
create view
drop index
show view
with grant option  #能将自己获得的权限转增给其他用户
数据操作
select
insert
delete
update
字段级别
select(col1,col2,...)
update(col1,col2,...)
insert(col1,col2,...)
所有权限
all privileges 或 all
授权:grant
grant select(col1),insert (col1) on mydb.mytb1 to 'name'@'host';
取消授权:revoke
revoke delete on testdb.* from 'test'@'host';
查看指定用户获得的授权
help show grants
show grants for 'user'@'host';
show grants for CURRENT_USER[()];
注意:MariaDB服务进程启动时会读取mysql库中所有授权表至内存
(1) GRANT或REVOKE等执行权限操作会保存于系统表中,MariaDB的服务进程通常会自动重读授权
表,使之生效
(2) 对于不能够或不能及时重读授权表的命令,可手动让MariaDB的服务进程重读授权表:
mysql>FLUSH PRIVILEGES;
posted @ 2022-06-06 15:05  胖丿虎  阅读(103)  评论(0编辑  收藏  举报