Oracle系列-第二步:建表空间、用户及授权

Oracle notes
Some notes of Learning Oralce.


Oracle常用命令

切换用户
1
2
3
4
5
6
connect [用户名/密码@数据库名]
```

如:
```SQL
conn scott/tiger@orcl
显示当前用户
1
show user
显示表的结构
1
describe 表名

如:

1
desc scott.emp


创建表空间

格式:

1
create tablespace [表空间名] datafile ['文件路径'] size [文件大小];

如:

1
create tablespace mySpace datafile 'd:\mySpace.dbf' size 10m;

删除表空间:

1
drop tablespace myspace;


创建用户

格式:

1
create user [用户名] identified by [密码] default tablespace [默认表空间名]

如:

1
create user user1 identified by user1 default tablespace system

删除用户:

1
drop user user1


给用户授权

方式一:授予角色
  • connect : 登录
  • resource: 普通权限,用于操作
  • DBA: 管理员权限 (慎用)

如:

1
2
grant connect to user1
grant connect, resource to user1

方式二:授予单个权限

如:

  • 授予 user1 建表的权限

    1
    grant create table to user1
  • 授予 user1 删表的权限

    1
    grant drop table to user1
方式三:将某个对象的权限授予用户

如:

  • scott 用户的emp表的查询权限授予 user1:

    1
    grant select on scott.emp to user1
  • scott 用户的emp表的所有权限授予 user1:

    1
    grant all on scott.emp to user1

收回权限

回收用户的某项权限

1
revoke [权限] from [用户]

  • 收回 user1connect 权限

    1
    revoke connect from user1
  • 收回 user1emp 表的查询权限

    1
    revoke select on scott.emp from user1