用sqlplus为oracle创建表空间,创建用户,授权

1.首先启动服务(一定按顺序来)

先启动如下图第二个

再启动第一个

用sqlplus为oracle创建表空间,创建用户,授权

2.然后windows+r   cmd  进入doc窗口,输入sqlplus指令进入如下图,输入用户名以及口令

用sqlplus为oracle创建表空间,创建用户,授权

《1 创建表空间

 在D盘下创建一个student的表空间

要求5mb,可以自动增长的

create  tablespace  student        --创建表空间

datafile  ‘e:\student.dbf’    --指定表空间物理文件的存储位置

size  5M

autoextend  on;  --自动扩展

 

《2创建用户

 创建一个stu的用户,密码是stu

 默认的表空间是student

 建表t1 (age int)

create user stu   --用户名

identified by stu   --密码

default tablespace student;  --默认表空间

 

create table t1(

age int

)            --创建表t1

/      --为了执行命令,在sqlplus只有以分号结尾才可直接执行

 

《3授权

  授予stu 登陆的权限

  授予 stu 查询scott用户emp表的权限

 

grant connect to stu;  --授权

alter user scott account unlock;   --解锁

conn scott/tiger;   --切换用户

grant all on emp to stu;     --授权,这里的all 代表增删改查都已获取权限

conn stu/stu;     --切换用户

select * from scott.emp;          --查询成功

 

ok小例子完成,

我们来总结一下;

连接:conn system/口令;    conn /as sysdba;     conn scott/tiger;(密码默认为tiger,默认未解锁)    conn 用户名/口令;

查看当前用户: show user;

删除用户/表/表空间: drop user 用户名/table 表名/tablespace 表空间;

查看表结构: desc 表名;

修改密码:  create user username identified by newpassword;

 

授权: grant connect ,resource,dba to username;  

收权 :revoke connect ,resource,dba from username

授予用户创建session的权限,即登陆权限(与connect不同的是session只是一个会话的权限,关闭服务就没用了):

grant create session to 用户名;

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

授予创建表的权限:grant create table to username;

授予用户插入、删除,更新表的权限: grant insert/drop/update table to username;

 注意:即使以上是以管理员登陆并授权但还会提示权限不够,需要指定 "any"   

grant insert/drop/update any table to username;

授予用户查看指定表的权限:grant select on tablename to username;

 授予用户查看本用户下所有表的权限:    grant select any table to username;

授予删除/插入/修改表的权限:grant drop/insert /update  on tablename to username;

授予对指定表特定字段的插入和修改权限,注意,只能是insert和update:

grant insert(id)/update(id) on tablename to username;

授予用户alert任意表的权限:  grant alert all table to username;

操作用户的表:select * from username.tablename;