一、最常用导出导入方案—exp、imp命令工具
1、ssh工具连接服务器主机,exp命令导出
1.1将数据库全部数据导出
exp system/password@TestDB file=bak.dmp log=exp.log full=y
1.2 将数据库中system用户与sys用户的表导出
exp system/password@TestDB file=bak.dmp log=exp.log owner=(system,sys)
1.3 将数据库中的表 Table1,Table2 导出
exp system/password@TestDB tables="(table1,table2)" file=bak.dmp log=exp.log
1.4 将数据库中的表tableA中的字段filed1 值为 “王五” 的数据导出
exp system/password@TestDB tables=tableA query=' where filed1='王五' file=bak.dmp log=exp.log
注意:
2、ssh工具连接服务器主机,imp命令导入
2.1 全量导入dmp文件的数据:
imp system/password@TestDB file=bak.dmp log=imp.log ignore=y full=y
2.2 将一个用户所属的数据导入到另一个用户下:
imp system/manager@TestDB file=bak.dmp log=imp.log fromuser=seapark touser=seapark_copy
二、数据泵导出方法-expdp命令
1、ssh工具连接服务器主机,创建数据库目录对象-data_pump
create directory data_pump as '/u01/data_pump';
注意:
2、将目录DATA_PUMP的读写权限赋予xxx用户
grant read,write on directory DATA_PUMP to xxx;
3、expdp命令导出
(1)将table1,table2导出
expdp scott/tiger directory=DATA_PUMP dumpfile=emp1.dmp logfile=expdp1.log tables=table1,table2;
(2)按查询条件导出
将emp1表deptno为10的数据导出
expdp scott/tiger directory=DATA_PUMP dumpfile=condition.dmp logfile=condition.log tables=emp1 query=\' WHERE deptno\=\10\'
(3)按表空间导出
expdp \' / as sysdba \' directory=DATA_PUMP dumpfile=soe_tbs.dmp tablespaces=soe
(4)按用户导出
expdp \' / as sysdba \' directory=DATA_PUMP dumpfile=scott.dmp schemas=scott
(5)全库导出
expdp system/manager@orcl directory=dump_dir logfile=expdp1.log dumpfile=full.dmp full=y
注意:
二、数据泵导入方法-impdp命令
(1)将源端数据文件拷贝到目标端的目录下
scp 192.168.3.88:/u01/data_pump/* /u01/oracle/dir
(2)导入用户有变化
impdp \'/ as sysdba \' directory=DIR dumpfile=emp1.dmp remap_schema=scott:wr
(3)导入的表空间有变化
impdp \' / as sysdba \' directory=DIR dumpfile=tbs.dmp logfile=tbs.log remap_tablespace=abc:soe
四、目标库远程连接源库导入
①创建目录对象
create directory data_pump as '/u01/data_pump';
②授读写权限
grant read,write on directory DATA_PUMP to zyz;
③配置tnsnames
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxbora)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
④创建dblink
create public database link orcl18 connect to zyz identified by zyz using 'ORCL18';
select count(*) from zyz.userinfo@orcl18;
⑤导入数据
impdp zyz/zyz directory=data_pump network_link=orcl18 schemas=zyz logfile=zyz.log remap_tablespace=JCTABLESPACE:ZYZTABLESPACE exclude=statistics
⑥收集统计数据
exec dbms_stats.gather_schema_stats(ownname=>'ZYZ',estimate_percent=>10,degree=>8,cascade=>true,granularity=>'ALL');