用户需要什么用户权限才能在Oracle中运行GRANT SQL命令

vfhzx4xs  于 2022-09-18  发布在  Java
关注(0)|答案(1)|浏览(150)

我创建了一个用户“Usera”,并授予它CREATE SESSION、USER、TABLESPACE权限。现在以“USERA”身份登录,我已经成功地创建了另一个用户“USERB”,但无法向“USERB”运行授予特权,并出现错误:ORA-01031:特权不足。“用户A”应该拥有哪些权限才能运行GRANT语句?

z9smfwbn

z9smfwbn1#

这就是你目前拥有的(我想是这样的,因为你没有发布你到底做了什么):

作为特权用户(sys)连接,我正在创建一个被授予create sessioncreate user权限的新用户:

SQL> connect sys@pdb1 as sysdba
Enter password:
Connected.
SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS

SQL> create user usera identified by usera
  2  default tablespace users
  3  temporary tablespace temp
  4  quota unlimited on users;

User created.

SQL> grant create session, create user to usera;

Grant succeeded.

由于usera已被授予create user权限,因此允许其创建新用户-userb

SQL> connect usera/usera@pdb1
Connected.
SQL> create user userb identified by userb
  2  default tablespace users
  3  temporary tablespace temp
  4  quota unlimited on users;

User created.

但是,授予create session失败,因为不允许usera这样做:

SQL> grant create session to userb;
grant create session to userb

* 

ERROR at line 1:
ORA-01031: insufficient privileges

SQL>

那么,你能做什么呢?

一种选择是使用**with admin option**;返回到sys,并将其重新授予usera

SQL> connect sys@pdb1 as sysdba
Enter password:
Connected.
SQL> grant create session to usera with admin option;

Grant succeeded.

usera现在是否可以将create session授予userb?是!

SQL> connect usera/usera@pdb1
Connected.
SQL> grant create session to userb;

Grant succeeded.

SQL>

另一种选择是将**dba**角色授予usera

SQL> connect sys@pdb1 as sysdba
Enter password:
Connected.

usera中撤消create session级联到无法再创建会话的userb

SQL> revoke create session from usera;

Revoke succeeded.

只有usera具有CREATE SESSION权限:

SQL> grant create session to usera;

Grant succeeded.

但是,也要承认dba

SQL> grant dba to usera;

Grant succeeded.

usera现在可以将create session授予userb吗?是!

SQL> connect usera/usera@pdb1
Connected.
SQL> grant create session to userb;

Grant succeeded.

SQL>

然而:请注意,with admin optiondba都是强大的,如果您不注意,您的系统可能存在安全漏洞。只将强大的特权留给强大的用户;所有其他用户都不应该执行此类任务。

相关问题