暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第5天|学习用户的创建、查看、修改、删除

原创 杨凯同学 2021-12-06
680

1.创建用户user1、user2和user3,user1具有CREATEROLE权限,user2具有CREATEDB权限,要求使用两种不同的方法设置密码

omm=# create user user1 password 'yangkai_123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create user user2 identified by 'yangkai_123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
omm=# create user user3 identified by 'yangkai_123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE

omm=# alter user user1 CREATEROLE;
ALTER ROLE

omm=# alter user user2 createdb;
ALTER ROLE

2.修改用户user1的密码

omm=# alter user user1 identified by 'yangkai_9999' replace 'yangkai_123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
ALTER ROLE

3.重命名用户user2

omm=# alter user user2 rename to yangbaji9999;

4.将用户user1的权限授权给用户user3,再回收用户user3的权限

 grant user1 to user3;

omm=# \du user1;
List of roles
Role name | Attributes | Member of
-----------+-------------+-----------
user1 | Create role | {}

omm=# \du yangbaji9999
List of roles
Role name | Attributes | Member of
--------------+------------+-----------
yangbaji9999 | Create DB | {}

omm=# \du user3;
List of roles
Role name | Attributes | Member of
-----------+------------+-----------
user3 | | {user1}

omm=# revoke user1 from user3;
REVOKE ROLE
omm=# \du user3;
user3 | | {}

omm=# List of roles
Role name | Attributes | Member of

omm=# \du+
List of roles
Role name | Attributes | Member of | Description


omm=# --------------+------------------------------------------------------------------------------------------------------------------+-----------+-------------
gaussdb | Sysadmin | {} |
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} |
user1 | Create role | {} |
user3 | | {} |
yangbaji9999 | Create DB | {} |

yangkai 

5.删除所有创建用户

omm=# drop user user1;

DROP ROLE

omm=# drop user yangbaji9999;

DROP ROLE

omm=# drop user user3;
DROP ROLE

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论