天花板上的猫通过本文主要向大家介绍了linux,oracle,oracle 11g等相关知识,希望本文的分享对您有所帮助
使用数据泵IMPDP
(一)创建impdp模拟环境
1)在目标数据库服务器上创建一个目录用于impdp
mkdir$ORACLE_BASE/impdir
2)将源数据库expdp导出的文件复制到本地服务器上
scp oracle@192.168.100.10:/$ORACLE_BASE/expdir/*.dmp .
3)清除scott用户,从全备中导出
SQL>drop user scott cascade;
4)在目标数据库中创建一个目录指定到操作系统的目录上
SQL>create or replace directory scottimp as '/u01/app/oracle/impdir';
SQL>select * from dba_directories;
SQL>select * from dba_directories;
5)创建的目录必须授予用户读写目录的权限
SQL>GRANT read,write ON DIRECTORY scottimp TO public;
(二)从全备中导出scott用户
impdp system/oracle directory=scottimp dumpfile=dball%U.dmp schemas=scott
(三)导入scott用户的元数据,且不包含统计信息
SQL>drop user scott cascade
SQL> create user scott identified by scott account unlock;
SQL> grant connect,resource to scott;
impdp system/oracle directory=scottimp dumpfile=scott_meta.dmp logfile=impdp_scott_meta.log
SQL>select * from emp;
(四)导入scott用户的数据
在导入元数据后才可以导入数据
impdp system/oracle directory=scottimp dumpfile=scott_data.dmp logfile=impdp_scott_data.log
(五)只导入scott用户下的emph和dept表,已存在覆盖
impdp scott/scott directory=scottimp dumpfile=dball%U.dmp tables=emp,dept table_exists_action=replace
table_exists_action四个选项:
①APPEND:追加到现有表之后
②REPLACE:覆盖现有表
③SKIP:不覆盖现有表,跳过(默认)
④TRUNCATE:先截断现有表,之后导入数据
(六)使用DBLINK直接导入源数据库HR用户数据
1)源数据启动监听,目标数据库要配置tnsnames
2)目标数据库中创建DBLINK
a)SQL>CREATE PUBLIC DATABASE LINK link_hr10 CONNECT TO hr IDENTIFIED BY hr USING ‘conn10’
b)测试DBLINK
SQL>select* from employees@link_hr10
SQL>select* from employees@link_hr10
c) 对于经常使用的数据库链接,可以建立一个本地的同义词
SQL>CREATE SYNONYM hr_syn FOR employees@link_hr10;
SQL>select * from hr_syn;
SQL>CREATE SYNONYM hr_syn FOR employees@link_hr10;
SQL>select * from hr_syn;
3)直接导入源数据库中hr用户的表到本地目标数据scott用户中
I.赋予源数据库HR用户权限
a)SQL>grant imp_full_database to hr;
b)SQL>grant exp_full_database to hr;
II.目标数据库执行impdp导入
impdp scott/scott network_link=link_hr10 tables=hr.employees remap_schema=hr:scott