使用数据泵,进行数据导入导出

来源:互联网 发布:网络优化txwh123 编辑:程序博客网 时间:2024/04/28 23:36

1、数据导出(导出scott.emp)

  结果:d:\mydir下导出两个文件exp_scott_emp.dmpexp_scott_emp.log

(1)、    sys/changoninstall@ORCL连接

(2)、    新建目录:d:\mydir

(3)、    创建目录对象:create   directory   mydir as   'd:\mydir';

(4)、    对目录对象进行授权(授权给导出用户)

grant  read,write  on  directory  mydir  to  scott;

(5)、    创建导出的参数文件:exp_scott_emp.txt

userid=scott/tiger@orcldirectory=mydirdumpfile=exp_scott_emp.dmplogfile=emp_scott_emp.logtables=(emp)job_name=emp_scott_emp


(6)、    执行导出命令:用cmd进入命令提示符窗口,把命令提示符窗口的当前路径转到参数文件的存放路径下,引用刚创建的参数文件exp_scott_emp.txt来执行导出(expdp)命令(如d:\mydir\exp_scott_emp.txt

l  d:

l  cd  d:\mydir

l  expdp  parfile=exp_scott_emp.txt (注意:千万不要加分号;)

 

2、数据导入(导入scott.emp)

(1)、    准备导入源:d:\mydir

exp_scott_emp.dmp exp_scott_emp.log

(2)、    创建SQL脚本文件(beforeimp.sql):保存导入前在目标数据库中要执行的命令

--目录对象create   directory   mydir as   'd:\mydir';--表空间(D:\mydir\tablespace目录必须存在,且目录下不能存在将要创建的数据文件)create  tablespace  mytbsdatafile 'D:\mydir\tablespace\mytbs1.dbf'size 5M autoextend on next 1k maxsize 10M , 'D:\mydir\tablespace\mytbs2.dbf' size 10M ;--profilecreate profile myprofile limitpassword_life_time 30failed_login_attempts 6;--导入用户(创建导入用户)create user scottprofile myprofileidentified by tigerdefault tablespace mytbsaccount unlock;grant connect to scott;grant dba to scott; exit;--一定记得要退出


 

(3)、    创建导入参数文件:imp_scott_emp.txt

userid=scott/tiger@ORCLdirectory=mydirdumpfile=exp_scott_emp.dmplogfile=exp_scott_emp.logjob_name=imp_scott_emp


 

(4)、    创建导入的批命令文件:imp_scott.bat

sqlplus sys/changeoninstall@orcl as sysdba @beforeimp.sqlimpdp parfile=imp_scott_emp.txt

 

(5)、  执行imp_scott.bat:将创建的三个文件(beforeImp.sqlimp_scott_emp.txtimp_scott.bat)放到同一路径下,用cmd进入命令提示符窗口,将当前路径转到三个文件的路径下,输入:imp_scott.bat (注意,千万不要加分号;)

 

 

原创粉丝点击