一、 备份数据库
----连接数据库
sqlplus system/password as sysdba;
---创建或替换文件并保存在 C:\beifen 路径(新建一个文件夹)
create or replace directory copy as 'C:\beifen';
----赋予读写功能
Grant read,write on directory copy to system;
----开始备份
expdp system/password@orcl directory=copy dumpfile=unifier.dat logfile=unifier.log schemas=unifier;
----查询数据库所用的表空间(这里查询到表空间是UNIFIER_TS)
select username,default_tablespace from dba_users where username='UNIFIER'
二、 还原数据库
----连接数据库
Sqlplus system/password as sysdba
----如果该数据库中已存在该用户,则删除 unifier
drop user unifier cascade;
----创建表空间
create tablespace UNIFIER_TS datafile 'D:\app\oracle\oradata\orcl\UNIFIER_TS.dbf' size 4096M reuse autoextend on next 100M maxsize unlimited logging default nocompress online extent management local autoallocate segment space management auto;
-----创建临时表空间
create temporary tablespace gateway_temp tempfile 'D:\app\oracle\oradata\orcl\gateway _temp.dbf' size 2048M reuse autoextend on next 50M maxsize unlimited extent management local uniform size 1M;
----创建用户
create user unifier identified by password profile default account unlock default tablespace UNIFIER_TS temporary tablespace gateway_temp quota unlimited on UNIFIER_TS;
----给用户授权
grant dba,connect,resource,create view,create table to unifier;
----创建目录 sql(如果已经创建过了,就不要再创建了) 注意下面路径,是用来存放还原文件路径的地方,其中 file_path 变量在还原时候还需要用 到,且与还原语句要保持一致
create or replace directory beifen as 'C:\app\beifen';
Grant read,write on directory beifen to system;
----还原数据库,注意还原文件名称必须和 file_path 指定路径下的文件名称一致
impdp system/Dms123456@orcl directory=beifen dumpfile=unifier.dat REMAP_SCHEMA=unifier:unifier remap_tablespace=unifier:UNIFIER_TS,unifier_temp: gateway_temp;
REMAP_SCHEMA,注意冒号前的分别是源库的用户名称,源库的用户表空间,源库的临时 表空间,而冒号后的分别是目标库的用户名称,目标库的用户表空间,目标库的临时表空间。
三、 删除表空间以及用户
----删除用户
drop user unifier cascade
----删除表空间。
drop tablespace tablespace_name including contents and datafiles;