一、Oracle介绍
1、Oracle简介
2、Oracle版本
3、四大特点
Oracle数据库具有完整的数据库管理功能、完备关系的产品以及具有分布式处理能力的数据库。
它对数据的可靠性、大量性、持久性、共享性提供了一套可靠的解决方案、而且可以轻松支持多用户、大事务量的事务处理。
它的优点就是可用性强、可扩展性强、数据安全性强、稳定性高,以及现阶段12C支持分布式数据处理。
它提供了一套严禁的逻辑结构、文件结构、相关恢复技术的解释和实现。
4、Oracle体系结构
二、Oracle 安装
三、客户端工具使用
1、SQL Plus工具
2、SQL*Plus 命令行工具
3、PL/SQL Developer 工具
四、服务
1、启动服务
2、服务实例名设置
五、用户
1、以系统管理员登陆数据库:sqlplus system/a123456@orcl
2、解锁系统自带用户scott, 切换连接并设置密码为tiger
锁定用户:ALTER USER 用户名 ACCOUNT LOCK;
解锁用户: ALTER USER 用户名 ACCOUNT UNLOCK;
切换用户(connect 可以简写conn):connect username/password@serviceName [ as 连接身份]
查看当前用户:show user;
select table_name from user_tables; //当前用户拥有的表
select * from tab; //当前用户拥有的表
select table_name from all_tables; //所有用户的表
select table_name from dba_tables; //包括系统表
select table_name from dba_tables where owner='用户名'; //指定用户退出登录:quit;
3、Oracle用户创建(删除)
sqlplus system/a123456@orcl as sysdba; -- 连接数据库(管理员角色)。
-- 创建用户
create user jalen -- 用户名
identified by "a123456" -- 密码
default tablespace USERS -- 表空间名
temporary tablespace temp -- 临时表空间名
profile DEFAULT -- 数据文件(默认数据文件)
account unlock; -- 账户是否解锁(lock:锁定、unlock解锁)
-- 连接登陆测试
conn jalen/a123456@orcl
-- 删除用户
drop user student; -- 删除student用户(student:用户名)
复制
CONNECT角色:connect角色是Oracle用户的基本角色,connect权限代表着用户可以和Oracle服务器进行连接,建立session(会 话)。
RESOURCE角色:resouce角色是开发过程中常用的角色。RESOURCE给用户提供了可以创建自己的对象,包括:表、视图、序列、过程、触发器、索引、包、类型等。
DBA角色:DBA角色是管理数据库管理员该有的角色。它拥护系统了所有权限,和给其他用户授权的权限。SYSTEM用户就具有DBA权限。
系统权限:比如:create session可以和数据库进行连接权限、create table、create view 等具有创建数据库对象权限。
对象权限:比如:对表中数据进行增删改查操作,拥有数据库对象权限的用户可以对所拥有的对象进行相应的操作。
系统权限只能通过DBA用户授权!所以通常用于连接的用户(sqlplus system/a123456 as sysdba; )
对象权限由拥有该对象权限的对象授权!
数据库角色选择授权一般也只能通过DBA用户授权!(sqlplus system/a123456 as sysdba;)
用户不能自己给自己授权!(所以授权可以统一的:sqlplus system/a123456 as sysdba;)
4、授权语句:grant...[on...] to...
--GRANT 数据库角色 TO 用户
grant connect to jalen;--授权connect角色(必须)
grant resource to jalen;--授予resource角色
grant dba to jalen; -- 授予管理员dba角色
--GRANT 用户的系统权限 to 用户
grant create session to jalen; -- 授予用户登录数据库的权限
-- 授予用户操作表空间的权限:
grant unlimited tablespace to jalen; -- 授予用户无限制的操作表空间的权限
grant create tablespace to jalen;
grant alter tablespace to jalen;
grant drop tablespace to jalen;
grant manage tablespace to jalen;
-- 授予用户操作表的权限:
grant create table to jalen; (包含有create index权限, alter table, drop table权限)
-- 授予用户操作视图的权限:
grant create view to jalen; (包含有alter view, drop view权限)
-- 授予用户操作触发器的权限:
grant create trigger to jalen; (包含有alter trigger, drop trigger权限)
-- 授予用户操作存储过程的权限:
grant create procedure to jalen;(包含有alter procedure, drop procedure 和function 以及 package权限)
-- 授予用户操作序列的权限:
grant create sequence to jalen; (包含有创建、修改、删除以及选择序列)
-- 授予用户回退段权限:
grant create rollback segment to jalen;
grant alter rollback segment to jalen;
grant drop rollback segment to jalen;
-- 授予用户同义词权限:
grant create synonym to jalen;(包含drop synonym权限)
grant create public synonym to jalen;
grant drop public synonym to jalen;
-- 授予用户关于用户的权限:
grant create user to jalen;
grant alter user to jalen;
grant become user to jalen;
grant drop user to jalen;
-- 授予用户关于角色的权限:
grant create role to jalen;
-- 授予用户操作概要文件的权限
grant create profile to jalen;
grant alter profile to jalen;
grant drop profile to jalen;
-- 允许从sys用户所拥有的数据字典表中进行选择
grant select any dictionary to jalen;
--GRANT 用户的对象权限 on 对象 TO 用户
grant select, insert, update, delete on JSQUSER to STUDENT;
--登陆scott用户把emp表的全部操作权限授予jalen用户
grant all on scott.emp to jalen;
复制
5、查看用户的权限或角色
(一)、查看用户
show user; //查看当前用户名
1.查看所有用户:
select * from dba_users;
select * from all_users;
select * from user_users; //查看当前用户
(二)、查看角色
1.当前用户被激活的全部角色
select * from session_roles;
2.当前当前用户被授予的角色
select * from user_role_privs;
3.全部用户被授予的角色
select * from dba_role_privs;
4.查看某个用户所拥有的角色
select * from dba_role_privs where grantee='用户名';
5.一个角色包含的系统权限
select * from dba_sys_privs where grantee='角色名'
select * from dba_sya_privs where grantee='COONNECT'; connect要大写
或者
select * from role_sys_privs where role='角色名'
select * from role_sys_privs where grantee='COONNECT'; connect要大写
6.一个角色包含的对象权限
select * from dba_tab_privs where grantee='角色名'
7.查看所有角色
select * from dba_roles;
(三)、查看权限
1.基本权限查询:
select * from session_privs; --当前用户所拥有的全部权限
select * from user_sys_privs;--当前用户的系统权限
select * from user_tab_privs;--当前用户的对象权限
select * from dba_sys_privs ;--查询某个用户所拥有的系统权限
select * from role_sys_privs;--查看角色(只能查看登陆用户拥有的角色)所包含的权限
2. 查看用户的系统权限(直接赋值给用户或角色的系统权限)
select * from dba_sys_privs;
select * from user_sys_privs;
3.查看用户的对象权限:
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
4.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
select * from v$pwfile_users;
补充
1、以下语句可以查看Oracle提供的系统权限
select name from sys.system_privilege_map
2、查看一个用户的所有系统权限(包含角色的系统权限)
select privilege from dba_sys_privs where grantee='SCOTT'
union
select privilege from dba_sys_privs where grantee in (select granted_role from dba_role_privs where grantee='SCOTT' );
3、 查询当前用户可以访问的所有数据字典视图。
select * from dict where comments like '%grant%';
4、显示当前数据库的全称
select * from global_name;
复制
6、取消用户权限:revoke...[on...] to...
-- Revoke 对象权限 on 对象 from 用户
revoke select, insert, update, delete on JSQUSER from jalen;
-- Revoke 系统权限 from 用户
grant create session to jalen; -- 授予用户登录数据库的权限
revoke SELECT ANY TABLE from jalen;
-- Revoke 角色(role) from 用户
revoke RESOURCE from jalen;
复制
7、修改用户密码、锁定状态
--修改用户信息
alter user jalen
identified by ****** --修改密码
account lock;--修改用户处于锁定状态或者解锁状态 (LOCK|UNLOCK )
复制