Oracle 11g 数据泵简易用法

导出标准库
说明: 范例中以tarara用户为例,要导出其他用户下的数据请把tarara替换成实际的用户名
0.源数据库服务器创建存放dmp文件的目录: 
   e:\backup\dmp
1.源数据库中创建目录名
   以dba身份登陆PLSQL Developer,执行如下语句
   create directory dpump_dir1 as 'e:\backup\dmp';
2.赋予tarara读写目录权限, PLSQL Developer中执行如下命令:
   grant read,write on directory dpump_dir1 to tarara;
   grant exp_full_database to tarara;
3.退出PLSQL Developer
4.导出所需的库
  在cmd中导出tarara用户下的所有数据:
  expdp tarara/tararapwd schemas=tarara  DIRECTORY=dpump_dir1 DUMPFILE=emp.dmp   COMPRESSION=ALL job_name=emp logfile=ca_expdp.log

  说明: 命令中的tarara为用户名, tararapwd为口令, 需要替换为正式使用的口令
        对于安装了oracle client和oracle数据库的系统, expdp命令可能会出错, 请搜索expdp命令,然后进入搜索到的以dbhome_1\bin结尾的目录下,比如
        cd E:\app\Administrator\product\11.2.0\dbhome_1\BIN
        再执行下面的命令:
        .\expdp tarara/tararapwd schemas=tarara  DIRECTORY=dpump_dir1 DUMPFILE=emp.dmp   COMPRESSION=ALL job_name=emp logfile=emp_expdp.log
5.查找并记录tarara 使用的表空间和临时表空间
   select username,default_tablespace,TEMPORARY_TABLESPACE from dba_users where username='tarara';
   select distinct(tablespace_name) from dba_segments where owner='tarara';

6.查看tarara使用的表空间的名称和大小, 在目标数据库上需要创建同样的表空间
select
    fs.tablespace_name  "Tablespace",
    (df.totalspace - fs.freespace)  "Used MB",
    fs.freespace   "Free MB",
    df.totalspace  "Total MB",
    round(100 * (fs.freespace / df.totalspace)) "Pct Free"
   from
     (select
        tablespace_name,
        round(sum(bytes)/1048576) TotalSpace
       from
         dba_data_files
      group by
        tablespace_name
     ) df,
     (select
        tablespace_name,
        round(sum(bytes)/1048576) FreeSpace
       from
         dba_free_space
      group by
        tablespace_name
      ) fs
   where df.tablespace_name=fs.tablespace_name
  order by "Pct Free";

导入标准库:
说明: 范例中以tarara用户为例,要导出其他用户下的数据请把tarara替换成实际的用户名
0.在目标服务器上创建存放导出文件的目录:
   d:\backup\dmp
1.把 源服务器 e:\backup\dmp目录下的 emp.dmp 文件复制到目标数据库服务器上
2.在目标服务器上创建tarara用户所需的表空间,表空间大小不得低于源表空间大小,
   以dba身份登陆PLSQL Developer,执行如下语句
   create tablespace emr datafile 'D:\EMRDATA\EMR\emr01.dbf' size 2048M;
   create temporary tablespace emr_temp tempfile 'D:\EMRDATA\EMR\EMR_TEMP.DBF' size 2000M ; 
3.创建需要导入的用户tarara
   create user tarara identified by tararapwd default tablespace emr temporary tablespace emr_temp account unlock;
   grant connect, resource to tarara;
   grant dba to tarara;
   grant imp_full_database to tarara;
   revoke unlimited tablespace from tarara;
   alter user tarara quota unlimited on emr;
4.目标数据库上创建目录
   create directory dpump_dir1 as 'd:\backup\dmp';
5.赋予tarara读写目录权限
   grant read,write on directory dpump_dir1 to tarara;
   grant imp_full_database to tarara;
6.退出PLSQL Developer
7.在目标数据库服务器的cmd中执行
   impdp tarara/tararapwd DIRECTORY=dpump_dir1 DUMPFILE=exp.dmp schemas=tarara  table_exists_action=append version=11.0.2.1 job_name=imp_dp

说明:
   如果无法导入空表则用sys用户或有dba权限用户执行下面的语句
   select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null
   此语句会生成一批可执行的语句,在SQL*Plus中逐条执行查询语句生成的alter table 语句;
   对于安装了oracle client和oracle数据库的系统, expdp命令可能会出错, 请搜索expdp命令,然后进入搜索到的以dbhome_1\bin结尾的目录下,比如
        cd E:\app\Administrator\product\11.2.0\dbhome_1\BIN
        再执行下面的命令:
        .\impdp tarara/tararapwd DIRECTORY=dpump_dir1 DUMPFILE=exp.dmp schemas=tarara  table_exists_action=append version=11.0.2.1 job_name=imp_dp

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值