show databases;
use mysql;
show tables;
desc user;
select * from user;
-- 创建用户
create user tom identified by 'password';
create user jerry identified by 'password';
-- 赋予权限
grant select(sname,ssex,sdept) on stu.student to tom with grant option;
-- 收回权限
revoke select(sname) on stu.student from jerry;
-- 查看权限
show grants for tom;
-- 创建角色
create role s_admin;
-- 赋予角色权限
grant select,insert,update on stu.student to s_admin;
show grants for s_admin;
select current_role();
-- 角色激活
show variables like 'activate_all_roles_on_login';
set global activate_all_roles_on_login = on;
-- set default role激活
set default role all to jerry;
-- 收回角色权限
revoke update on stu.student from s_admin;
-- 赋予用户角色
grant s_admin to jerry;
-- 收回用户角色
MySQL基础语句4-用户和角色
于 2022-11-04 19:14:24 首次发布
本文介绍MySQL中如何通过SQL语句创建用户、分配权限、管理角色等操作。包括创建用户、授权特定字段的查询权限、撤销权限、创建角色及管理角色权限等内容。
1440

被折叠的 条评论
为什么被折叠?



