须知:本文中Oracle版本为Oracle 11g,操作系统为windows 7及以上

使用准备

新建数据库实例

开始Oracle - OraDb11g_home1配置和移植工具Database Configuration Assistant

根据提示点击下一步,在步骤 4时,记得关闭Enterprise Manager 自动维护任务 指定快速恢复区,因为在开发环境下,不需要使用到这些功能,避免消耗额外的资源

剩下的根据提示完成即可,完成后在cmd中输入

sqlplus system/your_password@your_database_name

若显示连接到your_database_name则说明创建成功

编写脚本

Oracle数据库是非常占用系统资源的,如果不设置为手动,将会在开机时给电脑带来很大的压力

计算机右键管理服务和应用程序服务

将所有Oracle开头的服务全部设定为手动

开启脚本

#开启Oracle监听
net start OracleOraDb11g_home1TNSListener
#开启对应数据库服务
net start your_service_name

关闭脚本

#关闭对应数据库服务
net stop your_service_name

创建表空间

CREATE TABLESPACE MAXDATA DATAFILE 'your_location'  SIZE  1600M AUTOEXTEND ON;
CREATE TABLESPACE MAXINDEX DATAFILE 'your_location' SIZE  800M AUTOEXTEND ON;
CREATE TEMPORARY TABLESPACE MAXTEMP TEMPFILE 'your_location' SIZE  300M AUTOEXTEND ON MAXSIZE unlimited;

新建用户并授权

-- 新建用户
Create user your_user_name identified by your_user_password;
-- 设定表空间
alter user your_user_name default tablespace MAXDATA quota unlimited on MAXDATA;
alter user your_user_name quota unlimited on MAXINDEX;
alter user your_user_name temporary tablespace MAXTEMP;
-- 授权
grant create job to your_user_name; 
grant create trigger to your_user_name; 
grant create session to your_user_name; 
grant create sequence to your_user_name; 
grant create synonym to your_user_name; 
grant create table to your_user_name; 
grant create view to your_user_name; 
grant create procedure to your_user_name; 
grant alter session to your_user_name;
grant execute on ctxsys.ctx_ddl to your_user_name;      
grant dba to your_user_name;

数据导入

数据导入分两种,常规导入和数据泵导入,数据泵导出
数据泵导出的数据只能数据泵导入,常规导出的数据只能常规导入

数据泵导入

创建目录,并授权给maximo用户

create or replace directory location_name as 'your_location';
grant all on directory location_name to maximo;

将数据文件复制进上述文件夹

开始导入

-- 注意 your_data_file_name 是文件名称不包含路径
$impdp your_user_name/your_user_password@sid schemas=maximo directory=maximo dumpfile=your_data_file_name 

常规导入

直接导入

$imp your_user_name/your_user_password@sid fromuser=maximo touser = maximo file =your_data_location log=your_log_location buffer=128000

数据导出

直接导出

exp your_user_name/your_user_password@sid owner=your_user_name file=your_data_location 

数据泵导出

如上方数据泵导入,会在用户事先指定的目录下进行操作

开始导出

-- 注意 your_data_file_name 是文件名称不包含路径
expdp your_user_name/your_user_password@sid schemas=maximo dumpfile=your_data_file_name directory=maximo

删库

在Oracle数据库中,表是存储在用户的表空间下的,所以如果删除了用户,就相当于删库

drop user user_name cascade;

数据回闪

对于oracle而言,当你对数据表有了误操作(错误的删除,修改),就可以使用数据回闪功能,让你的表回到指定日期的样子

--查询指定时间表的数据
select * from 表名 as of timestamp to_timestamp('时间', 'yyyy-mm-dd hh24:mi:ss');

如果查得到,那么就可以开始回闪了

--为数据表开启回闪功能
alter table 表名 enable row movement;
--对数据表进行回闪操作
flashback table 表名 to timestamp TO_TIMESTAMP('回闪时间点', 'yyyy-mm-dd hh24:mi:ss');
--关闭回闪功能
alter table 表名 disable row movement;

Q.E.D.


此 生 无 悔 恋 真 白 ,来 世 愿 入 樱 花 庄 。