管理用户

1.创建、授权、连接用户。

[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Jun 11 05:18:45 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> sho user
USER is "SYS"
SQL> create user blake identified by blake;

User created.

SQL> conn blake/blake
#blake用户还没有任何权限,不能做任何事,连接也不行。
ERROR:
ORA-01045: user BLAKE lacks CREATE SESSION privilege; logon denied


Warning: You are no longer connected to ORACLE.
SQL> conn / as sysdba
Connected.
SQL> grant create session to blake;
#给blake用户授予相关权限
Grant succeeded.

SQL> conn blake/blake
Connected.
SQL> 

[oracle@localhost ~]$ sqlplus blake/blake

SQL*Plus: Release 11.2.0.3.0 Production on Mon Jun 11 06:17:43 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show user
USER is "BLAKE"
SQL> create table test (id varchar2(10),age number);
create table test (id varchar2(10),age number)
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> conn / as sysdba
Connected.
SQL> grant create table to blake;

Grant succeeded.

SQL> conn blake/blake
Connected.
SQL> create table test (id varchar2(10),age number);

Table created.

SQL> 

2.撤回权限。

[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Jun 11 23:11:03 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> conn blake/blake
Connected.

SQL> create table test2 (id varchar2(10),age number);

Table created.

SQL> conn / as sysdba
Connected.

SQL> revoke create table from blake;

Revoke succeeded.

SQL> conn blake/blake
Connected.
SQL> create table test3 (id varchar2(10),age number);
#blake用户创建表的权限已经被撤回,所以不能再创建表了。
create table test3 (id varchar2(10),age number)
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> 

3.改用户密码。

SQL> conn scott/tiger
#密码错误
ERROR:
ORA-01017: invalid username/password; logon denied


SQL> conn / as sysdba
Connected.
SQL> alter user scott identified by tiger;
#将scott的密码改为tiger
User altered.

SQL> conn scott/tiger 
Connected.


SQL> alter user scott identified by oracle;
#scott用户可以改自己的密码
User altered.

SQL> conn blake/blake
Connected.
SQL> alter user scott identified by scott;
#blake用户不能改scott用户的密码
alter user scott identified by scott
                               *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> conn / as sysdba
Connected.
SQL> alter user scott identified by scott;
#sys用户相当于root,能改任何用户的密码。
User altered.

SQL> conn scott/scott
Connected.
SQL> alter user scott identified by oracle;

User altered.

SQL> password
#可以使用password命令改密码
Changing password for SCOTT
Old password: 
New password: 
Retype new password: 
Password changed
SQL> conn / as sysdba
Connected.
SQL> conn scott/abc
Connected.

SQL> conn / as sysdba
Connected.
SQL> alter user scott identified by oracle;

User altered.

SQL> password blake
Changing password for blake
New password: 
Retype new password: 
Password changed
SQL> conn blake/oracle
Connected.
SQL> 

4.查看用户信息,删除用户。

SQL> select * from user_users;
#查看当前用户信息
USERNAME              USER_ID ACCOUNT_STATUS           LOCK_DATE EXPIRY_DA
------------------------------ ---------- -------------------------------- --------- ---------
DEFAULT_TABLESPACE         TEMPORARY_TABLESPACE       CREATED
------------------------------ ------------------------------ ---------
INITIAL_RSRC_CONSUMER_GROUP
------------------------------
EXTERNAL_NAME
----------------------------------------------------------------------------------------------------
SYS                 0 OPEN                       27-NOV-18
SYSTEM                 TEMP               17-SEP-11
SYS_GROUP



SQL> select * from all_users;
#查看系统所有用户
USERNAME              USER_ID CREATED
------------------------------ ---------- ---------
OPS$TOM                    86 11-JUN-18
OPS$ORACLE                 85 11-JUN-18
BLAKE                      84 11-JUN-18
SCOTT                      83 17-SEP-11
OWBSYS                     78 17-SEP-11
APEX_030200                77 17-SEP-11
APEX_PUBLIC_USER               75 17-SEP-11
FLOWS_FILES                74 17-SEP-11
MGMT_VIEW                  73 17-SEP-11
SYSMAN                     71 17-SEP-11
SPATIAL_CSW_ADMIN_USR              69 17-SEP-11

USERNAME              USER_ID CREATED
------------------------------ ---------- ---------
SPATIAL_WFS_ADMIN_USR              66 17-SEP-11
MDDATA                     64 17-SEP-11
OWBSYS_AUDIT                   82 17-SEP-11
OLAPSYS                    60 17-SEP-11
MDSYS                      57 17-SEP-11
SI_INFORMTN_SCHEMA             56 17-SEP-11
ORDPLUGINS                 55 17-SEP-11
ORDDATA                    54 17-SEP-11
ORDSYS                     53 17-SEP-11
ANONYMOUS                  46 17-SEP-11
XDB                    45 17-SEP-11

USERNAME              USER_ID CREATED
------------------------------ ---------- ---------
CTXSYS                     43 17-SEP-11
EXFSYS                     42 17-SEP-11
XS$NULL                2147483638 17-SEP-11
WMSYS                      32 17-SEP-11
APPQOSSYS                  31 17-SEP-11
DBSNMP                     30 17-SEP-11
ORACLE_OCM                 21 17-SEP-11
DIP                    14 17-SEP-11
OUTLN                   9 17-SEP-11
SYSTEM                  5 17-SEP-11
SYS                 0 17-SEP-11

33 rows selected.

SQL> conn blake/oracle
Connected.
SQL> select * from tab;

TNAME                  TABTYPE  CLUSTERID
------------------------------ ------- ----------
TEST                   TABLE
TEST2                  TABLE
TEST3                  TABLE

SQL> conn / as sysdba
Connected.
SQL> drop user blake cascade;
#删除用户及关联数据
User dropped.

SQL> conn blake/oracle
ERROR:
ORA-01017: invalid username/password; logon denied


Warning: You are no longer connected to ORACLE.
SQL> roll
ERROR:
ORA-01012: not logged on

SQL> rollback;
SP2-0640: Not connected
SQL> show user;
USER is ""
SQL> conn / as sysdba
Connected.
SQL> roll    
Rollback complete.
SQL> conn blake/oracle
#删除的用户,回滚不能还原。
ERROR:
ORA-01017: invalid username/password; logon denied


Warning: You are no longer connected to ORACLE.

SQL> conn / as sysdba
Connected.
SQL> select * from all_users;

USERNAME              USER_ID CREATED
------------------------------ ---------- ---------
OPS$TOM                    86 11-JUN-18
OPS$ORACLE                 85 11-JUN-18
SCOTT                      83 17-SEP-11
OWBSYS                     78 17-SEP-11
APEX_030200                77 17-SEP-11
APEX_PUBLIC_USER               75 17-SEP-11
FLOWS_FILES                74 17-SEP-11
MGMT_VIEW                  73 17-SEP-11
SYSMAN                     71 17-SEP-11
SPATIAL_CSW_ADMIN_USR              69 17-SEP-11
SPATIAL_WFS_ADMIN_USR              66 17-SEP-11

USERNAME              USER_ID CREATED
------------------------------ ---------- ---------
MDDATA                     64 17-SEP-11
OWBSYS_AUDIT                   82 17-SEP-11
OLAPSYS                    60 17-SEP-11
MDSYS                      57 17-SEP-11
SI_INFORMTN_SCHEMA             56 17-SEP-11
ORDPLUGINS                 55 17-SEP-11
ORDDATA                    54 17-SEP-11
ORDSYS                     53 17-SEP-11
ANONYMOUS                  46 17-SEP-11
XDB                    45 17-SEP-11
CTXSYS                     43 17-SEP-11

USERNAME              USER_ID CREATED
------------------------------ ---------- ---------
EXFSYS                     42 17-SEP-11
XS$NULL                2147483638 17-SEP-11
WMSYS                      32 17-SEP-11
APPQOSSYS                  31 17-SEP-11
DBSNMP                     30 17-SEP-11
ORACLE_OCM                 21 17-SEP-11
DIP                    14 17-SEP-11
OUTLN                   9 17-SEP-11
SYSTEM                  5 17-SEP-11
SYS                 0 17-SEP-11

32 rows selected.


SQL> 

5.开放和关闭指定表的查询权限


[oracle@localhost ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jun 12 03:25:16 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create user blake identified by oracle;

User created.

SQL> grant create session to blake;

Grant succeeded.

SQL>  grant create table to blake;

Grant succeeded.

SQL> conn blake/oracle
Connected.
SQL> create table test (id varchar2(10),age number);

Table created.

SQL> select * from tab;

TNAME                  TABTYPE  CLUSTERID
------------------------------ ------- ----------
TEST                   TABLE



SQL> select * from scott.emp;
#blake用户对scott.emp表没有查询权限
select * from scott.emp
                    *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> conn / as sysdba
Connected.
SQL> 
SQL> grant select on scott.emp to public;
#开放scott.emp表的查询权限
Grant succeeded.

SQL> conn blake/oracle
Connected.
SQL> select * from scott.emp;
#scott.emp的查询权限已开放
     EMPNO ENAME      JOB          MGR HIREDATE     SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK       7902 17-DEC-80        800            20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300     30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500     30
      7566 JONES      MANAGER         7839 02-APR-81       2975            20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400     30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850            30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450            10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000            20
      7839 KING       PRESIDENT        17-NOV-81       5000            10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500      0     30
      7876 ADAMS      CLERK       7788 23-MAY-87       1100            20

     EMPNO ENAME      JOB          MGR HIREDATE     SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7900 JAMES      CLERK       7698 03-DEC-81        950            30
      7902 FORD       ANALYST         7566 03-DEC-81       3000            20
      7934 MILLER     CLERK       7782 23-JAN-82       1300            10

14 rows selected.



SQL> conn / as sysdba
Connected.
SQL> revoke select on scott.emp from public;

Revoke succeeded.

SQL> conn blake/oracle
Connected.
SQL> select * from scott.emp;
#scott.emp的查询权限已关闭
select * from scott.emp
                    *
ERROR at line 1:
ORA-00942: table or view does not exist

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,392评论 5 470
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,258评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,417评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,992评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,930评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,199评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,652评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,327评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,463评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,382评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,432评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,118评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,704评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,787评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,999评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,476评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,057评论 2 341

推荐阅读更多精彩内容