您的位置:首页 > 其它

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

2013-06-24 10:15 351 查看
1、数据导出(导出scott.emp)

  结果:d:\mydir下导出两个文件exp_scott_emp.dmp和exp_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@orcl
directory=mydir
dumpfile=exp_scott_emp.dmp
logfile=emp_scott_emp.log
tables=(emp)
job_name=emp_scott_emp


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


d:


cd  d:\mydir


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  mytbs
datafile
'D:\mydir\tablespace\mytbs1.dbf'
size 5M
autoextend on next 1k
maxsize 10M ,
'D:\mydir\tablespace\mytbs2.dbf'
size 10M ;

--profile
create profile myprofile limit
password_life_time 30
failed_login_attempts 6;

--导入用户(创建导入用户)
create user scott
profile myprofile
identified by tiger
default tablespace mytbs
account unlock;
grant connect to scott;
grant dba to scott;
exit;--一定记得要退出


 

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

userid=scott/tiger@ORCL
directory=mydir
dumpfile=exp_scott_emp.dmp
logfile=exp_scott_emp.log
job_name=imp_scott_emp


 

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

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

 

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

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: