oracle笔记——第四天:数据库管理

来源:互联网 发布:聚合数据使用必须认证 编辑:程序博客网 时间:2024/05/19 16:49
作为一个oracle管理员,不会备份数据,恢复数据  这是很可怕的
每一个oracle数据库  应该至少有一个管理员(DBA  数据库管理 databases manager)
( 数据库 和 网络  也来也重视 )
数据管理员职责
1、安装升级数据库
2、建表、表空间、视图、索引、、、
3、制定备份恢复数据
4、数据库的权限管理,调优、故障排除
5、对于高级dba,要求能参与项目的开发,会编写sql 语句  存储过程、规则、约束、触发器;

sys(相当于董事长  ,对应sys方案) sys(数据库管路员角色) sysdba(系统管理员) sysoper(系统操作员)
system(相当于总经理 对应system方案)  sys(数据库管路员角色) sysdba(系统管理员)  没有操作员的权限
--区别
1、存储数据的重要性不同
2、权限不同
sysdba>sysoper(不能创建数据库,只能完全恢复数据,不能部分恢复)>dba
管理初始化参数
show parameter(显示参数)
数据的恢复和备份(逻辑备份(open状态),物理备份)
---导出
--1、导出表
--2、导出方案(一个用户对应一个方案)
--3、导出数据库
--使用命令 exp(  userid、tables、owner、full=y、inctype、rows、file)
--1.0、导出自己表(到oracle/bin路径下) 一张表   多张表
exp userid=scott/tiger@orcl tables=(emp) file=d:\e1.dmp;
--1.1、导出别人的表(一定要在dba的权限  sysdba  sys)(scott.emp  哪个用户的那张表)
exp userid=system/manager@orcl tables=(scott.emp) file=d:\e2.dmp;
--1.2、导出表结构(在上面的基础上加上rows=n)
exp userid=scott/tiger@orcl tables=(emp) file=d:\e1.dmp rows=n;
--1.3、直接导出方式(只需要在后面加上  direct=y 这种方式比默认方式的速度要快 ,导出大量数据时,可以考虑)
exp userid=scott/tiger@orcl tables=(emp) file=d:\e1.dmp direct=y;
--2.1、导出自己的方案
exp userid=scott/tiger@orcl owner=scott file=d:\e1.dmp;
--2.2、导出别人的方案(导出别人方案需要dba的权限)
exp system/manager owner=(system,scott) file=d:\e1.dmp;
--3.1、导出数据库(inctype=complete  增量备份)
exp userid=system/manager@orcl full=y inctype=complete file=x.dmp
---导入
--1、导入表
--2、导入方案(一个用户对应一个方案)
--3、导入数据库
--使用命令  imp(userid,tables,formuser,touser,file,full=y,inctype,rows,ignore)
--1.1、导入自己的表
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp;
--1.2、导入表的其他用户
imp userid=system/manager@orcl tables=(emp) file=d:\xx.dmp touser=scott;
--1.3、导入表的结构
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp rows=n
--1.4、导入数据
imp userid=scott/tiger@orcl tables=(emp) file=d:\xxx.dmp ignore=y
--2.1、导入自己的方案
imp userid=scott/tiger file=d:\xx.dmp;
--2.2、导入其他方案
imp userid=system/manager file=d:\xxx.dmp fromuser=system touser=scott;
--3.1、导入数据库
imp userid=system/manager full=y file=d:\xxxx.dmp;
----------------------------------------------
----数据字典(静态)=基表+动态视图  动态性能视图(动态)
--数据字典(只可看,不可摸)  :记录了数据库的系统信息,它只是读表和视图的集合,(sys)
--数据字典分为三种类型(user_xxx,all_xxx,dba_xxx)
user_tables;all_tables;dba_tables;
select table_name from user_tables;(当前用户的表)
select table_name from all_tables;(当前用户可以访问到的表)
select tables_name from dba_tables;(dba 权限)
--用户名,权限,角色
dba_users;(显示所有用户)
dba_sys_privs;(显示用户具有的系统权限)
dba_tab_privs;(显示用户具有的对象权限)
dba_col_privs;(显示用户具有的列权限)
dba_role_privs;(显示用户所具有的角色)
---查询scott所具有的系统权限
select *form dba_sys_privs where GRANTEE='SCOTT';
---查询scott所具有的对象权限
select *form dba_tab_privs where GRANTEE='SCOTT'
--查询有哪些角色
select *from dba_roles;
---查询一个角色包含的系统权限
select *from dba_sys_privs where grantee='DBA'
---查询一个角色包含的对象权限
oracle   第四天   数据库管理
作为一个oracle管理员,不会备份数据,恢复数据  这是很可怕的
每一个oracle数据库  应该至少有一个管理员(DBA  数据库管理 databases manager)
( 数据库 和 网络  也来也重视 )
数据管理员职责
1、安装升级数据库
2、建表、表空间、视图、索引、、、
3、制定备份恢复数据
4、数据库的权限管理,调优、故障排除
5、对于高级dba,要求能参与项目的开发,会编写sql 语句  存储过程、规则、约束、触发器;

sys(相当于董事长  ,对应sys方案) sys(数据库管路员角色) sysdba(系统管理员) sysoper(系统操作员)
system(相当于总经理 对应system方案)  sys(数据库管路员角色) sysdba(系统管理员)  没有操作员的权限
--区别
1、存储数据的重要性不同
2、权限不同
sysdba>sysoper(不能创建数据库,只能完全恢复数据,不能部分恢复)>dba
管理初始化参数
show parameter(显示参数)
数据的恢复和备份(逻辑备份(open状态),物理备份)
---导出
--1、导出表
--2、导出方案(一个用户对应一个方案)
--3、导出数据库
--使用命令 exp(  userid、tables、owner、full=y、inctype、rows、file)
--1.0、导出自己表(到oracle/bin路径下) 一张表   多张表
exp userid=scott/tiger@orcl tables=(emp) file=d:\e1.dmp;
--1.1、导出别人的表(一定要在dba的权限  sysdba  sys)(scott.emp  哪个用户的那张表)
exp userid=system/manager@orcl tables=(scott.emp) file=d:\e2.dmp;
--1.2、导出表结构(在上面的基础上加上rows=n)
exp userid=scott/tiger@orcl tables=(emp) file=d:\e1.dmp rows=n;
--1.3、直接导出方式(只需要在后面加上  direct=y 这种方式比默认方式的速度要快 ,导出大量数据时,可以考虑)
exp userid=scott/tiger@orcl tables=(emp) file=d:\e1.dmp direct=y;
--2.1、导出自己的方案
exp userid=scott/tiger@orcl owner=scott file=d:\e1.dmp;
--2.2、导出别人的方案(导出别人方案需要dba的权限)
exp system/manager owner=(system,scott) file=d:\e1.dmp;
--3.1、导出数据库(inctype=complete  增量备份)
exp userid=system/manager@orcl full=y inctype=complete file=x.dmp
---导入
--1、导入表
--2、导入方案(一个用户对应一个方案)
--3、导入数据库
--使用命令  imp(userid,tables,formuser,touser,file,full=y,inctype,rows,ignore)
--1.1、导入自己的表
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp;
--1.2、导入表的其他用户
imp userid=system/manager@orcl tables=(emp) file=d:\xx.dmp touser=scott;
--1.3、导入表的结构
imp userid=scott/tiger@orcl tables=(emp) file=d:\xx.dmp rows=n
--1.4、导入数据
imp userid=scott/tiger@orcl tables=(emp) file=d:\xxx.dmp ignore=y
--2.1、导入自己的方案
imp userid=scott/tiger file=d:\xx.dmp;
--2.2、导入其他方案
imp userid=system/manager file=d:\xxx.dmp fromuser=system touser=scott;
--3.1、导入数据库
imp userid=system/manager full=y file=d:\xxxx.dmp;
----------------------------------------------
----数据字典(静态)=基表+动态视图  动态性能视图(动态)
--数据字典(只可看,不可摸)  :记录了数据库的系统信息,它只是读表和视图的集合,(sys)
--数据字典分为三种类型(user_xxx,all_xxx,dba_xxx)
user_tables;all_tables;dba_tables;
select table_name from user_tables;(当前用户的表)
select table_name from all_tables;(当前用户可以访问到的表)
select tables_name from dba_tables;(dba 权限)
--用户名,权限,角色
dba_users;(显示所有用户)
dba_sys_privs;(显示用户具有的系统权限)
dba_tab_privs;(显示用户具有的对象权限)
dba_col_privs;(显示用户具有的列权限)
dba_role_privs;(显示用户所具有的角色)
---查询scott所具有的系统权限
select *form dba_sys_privs where GRANTEE='SCOTT';
---查询scott所具有的对象权限
select *form dba_tab_privs where GRANTEE='SCOTT'
--查询有哪些角色
select *from dba_roles;
---查询一个角色包含的系统权限
select *from dba_sys_privs where grantee='DBA'
---查询一个角色包含的对象权限
select *from dba_tab_privs where grantee='DBA'
----一个用户具有什么角色
select *from dba_role_privs where grantee='scott';
---表空间   数据文件
表空间是数据库的逻辑组成部分,从物理上讲
数据库春放在数据文件中
逻辑上讲,数据库这是存放表空间中,表空间有一个和多个文件组成
--oracle的逻辑结构 (表空间、段、区、块)
--建立表空间
create tablespace sp001 datafile 'd:\sp001.dbf' size 1M uniform size 128k;
--使用表空间
create table mypart(deptno number(2),dname varchar(2)) tablespace sp001;
--表空间的状态 (offline、online、read only)
--知道表空间的名字,显示表空间包含的表
select *from all_tables where tablespace_name='system';
--知道表名字,查看该表属于那个表空间
select tablespace_name,table_name from user_tables where table_name='emp';
--删除表空间
drop tablespace users;
--扩展表空间
1.增加数据文件
alter tablespace sp01 add datafile 'd:\text\sp01.dbf' szie20;
2.增加数据大小
alter tablespace 表空间名 'd:\test\sp01.dbf' reszie 20m
3.文件自动增长
alter tablespace 表空间名 'd:\text\sp01.dbf' autoextend on next 10M maxsize 500m;
--移动数据文件
(确定文件在那个表空间)select tables_name from dba_data_files where file_name='d:\sp01.dbf';
(是表空间脱机)alter tablespace sp01 offline;
(是文件移动到指定的目标位置)host move d:\sp001.dbf c:\test\sp001.dbf;
(移动数据文件)alter tablespace sp001 rename datafile 'd:\sp001.dbf' to 'c:\sp001.dbf';


























0 0
原创粉丝点击