Oracle中如何创建用户

发布时间:2021-06-21 15:04:11 作者:Leah
来源:亿速云 阅读:153

Oracle中如何创建用户,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创建用户和表空间:

1、登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用户)

2、以sysdba方式来打开sqlplus,命令如下: sqlplus / as sysdba

3、创建临时表空间:

--查询临时表空间文件的绝对路径。如果需要的话,可以通过查询来写定绝对路径。一般用${ORACLE_HOME}就可以了  
select name from v$tempfile;  
create temporary tablespace NOTIFYDB_TEMP tempfile '${ORACLE_HOME}\oradata\NOTIFYDB_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited;

4、创建表空间:

--查询用户表空间文件的绝对路径:
select name from v$datafile;
create tablespace NOTIFYDB datafile '${ORACLE_HOME}\oradata\notifydb.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

5、创建用户和密码,指定上边创建的临时表空间和表空间

create user hc_notify identified by hc_password default tablespace NOTIFYDB temporary tablespace NOTIFYDB_TEMP;

6、赋予权限

grant dba to hc_notify;
grant connect,resource to hc_notify;
grant select any table to hc_notify;
grant delete any table to hc_notify;
grant update any table to hc_notify;
grant insert any table to hc_notify;

经过以上操作,就可以使用hc_notify/hc_password登录指定的实例,创建我们自己的表了。

删除表空间:

1、查看用户权限

--查看用户要具备drop tablespace的权限,如果没有,先用更高级的用户(如sys)给予授权
select a2.username,a1.privilege from dba_sys_privs a1 , user_role_privs a2
where a1.privilege = 'DROP TABLESPACE'
and a1.grantee =a2.granted_role

2、删除临时表空间

复制代码
--查看临时表空间文件
select name from v$tempfile;
--查看用户和表空间的关系
select USERNAME,TEMPORARY_TABLESPACE from DBA_USERS;
--如果有用户的默认临时表空间是NOTIFYDB_TEMP的话,建议进行更改
alter user xxx temporary tablespace tempdefault;
---设置tempdefault为默认临时表空间
alter database default temporary tablespace tempdefault;
--删除表空间NOTIFYDB_TEMP及其包含数据对象以及数据文件
drop tablespace NOTIFYDB_TEMP including contents and datafiles;

3.删除用户表空间

--查看表空间文件
select name from v$datafile;
--停止表空间的在线使用
alter tablespace 表空间名称 offline;
--删除表空间NOTIFYDB_TEMP及其包含数据对象以及数据文件
drop tablespace NOTIFYDB_TEMP including contents and datafiles;

Oracle用户权限查询相关操作:

--查看所有的用户
select * from all_users;
--查看当前用户信息
select * from user_users;
--查看当前用户的角色
select * from user_role_privs;
--查看当前用户的权限
select * from user_sys_privs;
--查看当前用户的表可操作权限
select * from user_tab_privs;

--查看某一个表的约束,注意表名要 大写
select * from user_constraints where table_name='TBL_XXX';
--查看某一个表的所有索引,注意表名要 大写
select index_name,index_type,status,blevel from user_indexes where table_name = 'TBL_XXX';
--查看索引的构成,注意表名要 大写
select table_name,index_name,column_name, column_position FROM user_ind_columns WHERE table_name='TBL_XXX';

--系统数据字典 DBA_TABLESPACES 中记录了关于表空间的详细信息
select * from sys.dba_tablespaces;

--查看用户序列
select * from user_sequences;
--查看数据库序列
select * from dba_sequences;

案例

-- 创建临时表空间
create temporary tablespace PINGAN_TEMP tempfile '/u01/app/oracle/oradata/XE/PINGAN_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited;  
-- 创建表空间
create tablespace PINGAN datafile '/u01/app/oracle/oradata/XE/pingandb.dbf' size 200M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
-- 创建用户
create user pingan identified by pingan default tablespace SZNS temporary tablespace SZNS_TEMP;
-- 授权
grant dba to pingan;
grant connect,resource to pingan;
grant select any table to pingan;
grant delete any table to pingan;
grant update any table to pingan;
grant insert any table to pingan;

看完上述内容,你们掌握Oracle中如何创建用户的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. 02 oracle 创建用户和授权
  2. oracle12C 创建用户学习

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

oracle

上一篇:nginx部署vue项目找不到js css文件怎么办

下一篇:Python自动化工具tidevice的安装和使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》