《Oracle系列》Oracle SQL命令,创建用户、表空间,并赋予用户一系列权限

1. 创建用户

sql 复制代码
-- 创建一个名为ywgl的用户,并设置其密码为ywgl  
create user ywgl identified by ywgl;

2. 创建表空间

sql 复制代码
-- 创建一个名为TS_YWGL的表空间,数据文件存储在/home/u01/oradata/orcl/YWGL.dbf,  
-- 初始大小为1500M,当空间不足时自动扩展5M,最大大小为30000M  
create tablespace TS_YWGL datafile '/home/u01/oradata/orcl/YWGL.dbf' size 1500M autoextend on next 5M maxsize 30000M;

创建了一个名为TS_YWGL的表空间,并指定了数据文件的位置、初始大小、自动扩展参数和最大大小。

3. 设置用户默认表空间

sql 复制代码
-- 将ywgl用户的默认表空间设置为TS_YWGL  
alter user ywgl default tablespace TS_YWGL;

ywgl用户的默认表空间设置为TS_YWGL

4. 授权

sql 复制代码
-- 注意:下面的授权操作在逻辑上有些冗余,因为DBA角色包含了大部分权限  
-- 如果打算赋予用户DBA角色,那么以下单独的权限授予是不必要的  
  
-- 授予ywgl用户DBA权限(谨慎使用,这会给用户带来过大的权限)  
-- grant dba to ywgl; -- 注释掉或删除这行,除非你确实需要赋予DBA权限  
  
-- 单独授予ywgl用户一些权限(这些权限在DBA角色下是多余的)  
grant connect, resource to ywgl; -- 授予ywgl连接和资源的基本权限  
-- grant create session to ywgl; -- 这行是多余的,因为connect角色已经包含了create session权限  
grant create any sequence to ywgl; -- 允许ywgl创建任意序列  
grant create any table to ywgl; -- 允许ywgl创建任意表  
grant delete any table to ywgl; -- 允许ywgl删除任意表  
grant insert any table to ywgl; -- 允许ywgl向任意表插入数据  
grant select any table to ywgl; -- 允许ywgl查询任意表  
grant update any table to ywgl; -- 允许ywgl更新任意表  
grant unlimited tablespace to ywgl; -- 允许ywgl使用不受限制的表空间  
grant execute any procedure to ywgl; -- 允许ywgl执行任意存储过程  
grant create any view to ywgl; -- 允许ywgl创建任意视图  

注意:在实际应用中,应该仔细考虑需要授予哪些权限,并避免过度授权

5. 权限撤销

sql 复制代码
-- 撤销ywgl用户的DBA权限(如果之前授予了的话)  
revoke dba from ywgl; -- 如果之前授予了DBA权限,这里可以撤销它
相关推荐
zxrhhm10 小时前
PostgreSQL 中的层级查询 Oracle CONNECT BY 替代方案
数据库·postgresql·oracle
星马梦缘1 天前
数据库作战记录 实验7、8
数据库·sql·oracle
苍煜1 天前
一篇讲懂分库分表:概念、spirngboot实战
数据库·oracle
Jing_jing_X1 天前
MCP (一)是什么?一文讲清 AI 如何连接现实世界
数据库·人工智能·oracle
山峰哥2 天前
SQL优化从入门到精通:20个案例破解性能密码
数据库·sql·oracle·性能优化·深度优先
杨云龙UP2 天前
Windows Server 2012 环境下 Oracle 11.2 使用 expdp 实现自动备份、异地复制与定期清理_20260504
服务器·数据库·windows·mysql·docker·oracle·容器
IT邦德2 天前
OGG 26ai实时同步Oracle
数据库·oracle
苍煜2 天前
SpringBoot Spring事务完整版详解:@Transactional注解实操 + 七大事务传播机制用法
spring boot·spring·oracle
小李来了!2 天前
Navicate/plsql连接Oracle数据库教程
数据库·oracle
爬山算法2 天前
MongoDB(118)如何在升级过程中进行数据备份?
数据库·mongodb·oracle