在 Ubuntu + Oracle 数据库 环境中,“设权限”通常涉及 操作系统层(Linux 用户/组) 和 数据库层(Oracle 用户/角色/对象权限) 两部分。下面按常见场景说明。
Oracle 一般使用:
oracleoinstall、dba查看:
id oracle
将用户加入组:
sudo usermod -aG dba username
常见目录:
/u01/app/oracle
设置属主和权限:
sudo chown -R oracle:oinstall /u01
sudo chmod -R 775 /u01/app/oracle
dba$ORACLE_HOME/bin 执行权限sqlplus / as sysdba
或
sqlplus system/password
CREATE USER testuser IDENTIFIED BY password;
ALTER USER testuser IDENTIFIED BY newpassword;
ALTER USER testuser ACCOUNT LOCK;
ALTER USER testuser ACCOUNT UNLOCK;
GRANT CREATE SESSION TO testuser;
GRANT CREATE TABLE TO testuser;
GRANT CREATE VIEW TO testuser;
REVOKE CREATE TABLE FROM testuser;
假设有表 scott.emp
GRANT SELECT ON scott.emp TO testuser;
GRANT INSERT, UPDATE ON scott.emp TO testuser;
收回:
REVOKE SELECT ON scott.emp FROM testuser;
CREATE ROLE app_role;
GRANT CREATE SESSION, SELECT ANY TABLE TO app_role;
GRANT app_role TO testuser;
ALTER USER testuser QUOTA 100M ON users;
SELECT * FROM dba_sys_privs WHERE grantee='TESTUSER';
SELECT * FROM dba_tab_privs WHERE grantee='TESTUSER';
SELECT * FROM dba_role_privs WHERE grantee='TESTUSER';
✅ 不用 SYS / SYSTEM 做业务用户
✅ 用 角色 管理权限
✅ 最小权限原则
✅ 操作系统用户 ≠ 数据库用户
如果你能具体说明:
我可以给你更精确的操作步骤。