数据库的迁移

一、 备份数据库
----连接数据库

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; 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值