一、expdb 导出数据

一、创建目录

1.在数据库服务器建立真实目录

[oracle@localhost oracle]$ mkdir dmp

2.用管理员账号登录数据库

[oracle@localhost dmp]$ sqlplus / as sysdba

3.创建逻辑目录

SQL> create directory data_dir as '/data/app/oracle/dmp';

4.给要导出的用户的赋予该目录的操作权限

SQL> grant read,write on directory data_dir to user;

二、导出数据

用expdp导出dmp,有五种导出方式:

1.“full=y”,全量导出数据库

expdp user/passwd@orcl dumpfile=expdp.dmp directory=data_dir full=y logfile=expdp.log;

2.schemas按用户导出

expdp user/passwd@orcl schemas=user dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;

3.按表空间导出

expdp sys/passwd@orcl tablespace=tbs1,tbs2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;

4.导出表

expdp user/passwd@orcl tables=table1,table2 dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;

5.按查询条件导出

expdp user/passwd@orcl tables=table1='where number=1234' dumpfile=expdp.dmp directory=data_dir logfile=expdp.log;

三、导入数据

1.如果不是同一台服务器,需要先将上面的dmp文件下载到目标服务器上;

2.参照“expdp导出步骤”里的前三步,建立逻辑目录;

3.用impdp命令导入,对应五种方式:

a:“full=y”,全量导入数据库;

impdp user/passwd directory=data_dir dumpfile=expdp.dmp full=y;

b:同名用户导入,从用户A导入到用户A;

impdp A/passwd schemas=A directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;

c:①从A用户中把表table1和table2导入到B用户中;

impdp B/passwdtables=A.table1,A.table2 remap_schema=A:B directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;

②将表空间TBS01、TBS02、TBS03导入到表空间A_TBS,将用户B的数据导入到A,并生成新的oid防止冲突;

impdp A/passwdremap_tablespace=TBS01:A_TBS,TBS02:A_TBS,TBS03:A_TBS remap_schema=B:A FULL=Y transform=oid:n 
directory=data_dir dumpfile=expdp.dmp logfile=impdp.log

d:导入表空间;

impdp sys/passwd tablespaces=tbs1 directory=data_dir dumpfile=expdp.dmp logfile=impdp.log;

e:追加数据;

impdp sys/passwd directory=data_dir dumpfile=expdp.dmp schemas=system table_exists_action=replace logfile=impdp.log; 
--table_exists_action:导入对象已存在时执行的操作。有效关键字:SKIP,APPEND,REPLACE和TRUNCATE
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐