oracle创建用户、授权、建表空间

时间:2021-10-12 23:29:07
1.cmd
2.SQL> sqlplus/nolog;
3.SQL> conn/as sysdba;

4.//创建临时表DB_TEMP yx:我创建的数据库名称 在oracle安装目录下
SQL> CREATE TEMPORARY TABLESPACE DB_TEMP

TEMPFILE 'D:\app\Administrator\oradata\yx\DB_TEMP.DBF'

SIZE 32M

AUTOEXTEND ON

NEXT 32M MAXSIZE UNLIMITED

EXTENT MANAGEMENT LOCAL;

5. //创建数据表空间
SQL> CREATE TABLESPACE DB_DATA

LOGGING

DATAFILE 'D:\app\Administrator\oradata\yx\DB_DATA.DBF'

SIZE 32M

AUTOEXTEND ON

NEXT 32M MAXSIZE UNLIMITED

EXTENT MANAGEMENT LOCAL;

6. //创建登入用户
SQL> CREATE USER loginName IDENTIFIED BY password

ACCOUNT UNLOCK

DEFAULT TABLESPACE DB_DATA

TEMPORARY TABLESPACE DB_TEMP;

7.//给用户授权
SQL> GRANT CONNECT,RESOURCE TO 帐号; --表示把 connect,resource权限授予loginName 用户

SQL> GRANT DBA TO loginName ; --表示把 dba权限授予给NEWUSER用户



授予用户操作表空间的权限:

grant unlimited tablespace to loginName;

grant create tablespace to loginName;

grant alter tablespace to loginName;

grant drop tablespace to loginName;

grant manage tablespace to loginName;



授予用户操作表的权限:

grant create table to konglin; (包含有create index权限, alter table, drop table权限)

授予用户操作视图的权限:

grant create view to konglin; (包含有alter view, drop view权限)

授予用户操作触发器的权限:

grant create trigger to konglin; (包含有alter trigger, drop trigger权限)

授予用户操作存储过程的权限:

grant create procedure to konglin;(包含有alter procedure, drop procedurefunction 以及 package权限)

授予用户操作序列的权限:

grant create sequence to konglin;
(包含有创建、修改、删除以及选择序列)

授予用户回退段权限:

grant create rollback segment to konglin;

grant alter rollback segment to konglin;

grant drop rollback segment to konglin;

授予用户同义词权限:

grant create synonym to konglin;(包含drop synonym权限)

grant create public synonym to konglin;

grant drop public synonym to konglin;

授予用户关于用户的权限:

grant create user to konglin;

grant alter user to konglin;

grant become user to konglin;

grant drop user to konglin;

授予用户关于角色的权限:

grant create role to konglin;

授予用户操作概要文件的权限

grant create profile to konglin;

grant alter profile to konglin;

grant drop profile to konglin;

允许从sys用户所拥有的数据字典表中进行选择

grant select any dictionary to konglin;

grant create session to zhangsan;//授予zhangsan用户创建session的权限,即登陆权限

  grant unlimited tablespace to zhangsan;//授予zhangsan用户使用表空间的权限

  grant create table to zhangsan;//授予创建表的权限

  grante drop table to zhangsan;//授予删除表的权限

  grant insert table to zhangsan;//插入表的权限

  grant update table to zhangsan;//修改表的权限

  grant all to public;//这条比较重要,授予所有权限(all)给所有用户(public)

8.查看权限

  select * from user_sys_privs;//查看当前用户所有权限

  select * from user_tab_privs;//查看所用用户对表的权限
  
  select * from zhangsan.tablename// 操作表的用户的表
9.删除用户和表空间

步骤一:删除user
drop user ×× cascade
说明:删除了user,只是删除了该user下的schema objects,是不会删除相应的tablespace的。

步骤二: 删除tablespace
DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;


--删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
--删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
--删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles;
--删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;