一、不管导入还有导出都要先创建目录
1、登录plsql
sqlplus/nolog
conn sys/password@orcl as sysdba
2、创建目录
create directory myDir as 'd:yth';--生成目录(必须在指定位置先创建文件夹,名称最好与用户名一致)
yth:是目录名。必须手工创建。
2、增加权限
赋予目录读写权限 Grant read,write on directory myDir to yth;
yth:导入、导出的用户名
二、导出:
exit,退出plsql。然后操作如下
1、单用户导出
expdp yth/dcjet@orcl schemas=yth dumpfile=yth.dmp DIRECTORY=myDir logfile=expdp.log
2、多用户导出 (用sys用户)
expdp 'sys/syspwd@MyOrcl AS SYSDBA' directory=myDir schemas=(bshrp,portal,bsemr,bslis,pflis) dumpfile=hisdb.dmp logfile = hisdb.log;
三、导入:
1、
impdp zjgl/dcjet@orcl directory=myDir dumpfile=zjgl.dmp schemas=zjgl logfile=zjgl.log;
2、
impdp yth/dcjet@orcl directory=myDir dumpfile=yth.dmp logfile=a.log remap_schema=jzfw_data:yth remap_tablespace=jzfw_data:yth,users:yth,jcfz:yth
---remap_schema:旧用户:目标用户
---remap_tablespace:旧表空间:新表空间(多个的情况用逗号分隔)
3、多用户导入 (用sys用户)
impdp "sys/sys@MyOrcl AS SYSDBA" directory=myDir dumpfile=HISDB.DMP schemas=(bslis,bshrp,portal,bsemr,pflis) table_exists_action=replace logfile=impdp_hisdb.log
其中:table_exists_action:参数值有四种,解释如下:
1) skip:默认操作
2) replace:先drop表,然后创建表,最后插入数据
3) append:在原来数据的基础上增加数据
4) truncate:先truncate,然后再插入数据
下面是成功的例子(myDir),有时本地只有一个用例不用给@orcl:
impdp zjgl/dcjet@orcl directory=myDir dumpfile=zjgl.dmp schemas=zjgl logfile=zjgl.log;
impdp yth/dcjet directory=myDir dumpfile=ENTRY.DMP tables=data_ct.entry_head remap_schema=data_ct:yth remap_tablespace=data_center:yth
remap_schema 修改原数据dmp的用户,格式 【old :new】 如【XXX:LVAMS】
---tables 指定表名:原表用户.用表名
四、更多导出数据
1)按用户导
expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dir logfile=expdp.log
2)并行进程parallel
expdp scott/tiger@orcl directory=dir dumpfile=scott3.dmp parallel=40 job_name=scott3
3)按表名导
expdp scott/tiger@orcl TABLES=emp,dept dumpfile=expdp.dmp DIRECTORY=dir;
4)按查询条件导
expdp scott/tiger@orcl directory=dir dumpfile=expdp.dmp Tables=emp query='WHERE deptno=20';
5)按表空间导
expdp system/manager DIRECTORY=dir DUMPFILE=tablespace.dmp TABLESPACES=temp,example;
6)导整个数据库
expdp system/manager DIRECTORY=dir DUMPFILE=full.dmp FULL=y;
五、更多导入数据
1)导到指定用户下
impdp scott/tiger@orcl DIRECTORY=dir DUMPFILE=expdp.dmp SCHEMAS=scott logfile=impdp.log
2)改变表的owner
impdp system/manager DIRECTORY=dir DUMPFILE=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;
3)导入表空间
impdp system/manager DIRECTORY=dir DUMPFILE=tablespace.dmp TABLESPACES=example;
4)导入数据库
impdb system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;
5)追加数据
impdp system/manager DIRECTORY=dir DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION