-- 创建角色
create role if not exists 'chatRole'@'%';
create role if not exists 'chatReadRole'@'%';
-- 分配权限
grant all on chat.* to 'chatRole';
grant select on chat.* to 'chatReadRole';
-- 创建用户
create user 'chatdev'@'%' identified by 'chatdev';
create user 'chatreaddev'@'%' identified by 'chatreaddev';
-- 给用户分配权限
grant 'chatRole' to 'chatdev'@'%';
grant 'chatReadRole' to 'chatreaddev'@'%';
-- 查看用户权限信息
show grants for 'chatdev'@'%';
show grants for 'chatreaddev'@'%';
-- 查看用户分配角色权限信息
show grants for 'chatdev'@'%' using 'chatRole';
show grants for 'chatreaddev'@'%' using 'chatReadRole';