EXPDP和IMPDP的应用实例
2015-05-21 15:32:18 访问(1590) 赞(0) 踩(0)
EXPDP和IMPDP的应用实例
一、调用EXPDP
使用EXPDP工具时,其转储文件只能被存放在DIRECTORY对象对应的OS目录中,
而不能直接指定转储文件所在的OS目录。因此,使用EXPDP工具时,必须首先建
立DIRECTORY对象。并且需要为数据库用户授予使用DIRECTORY对象权限。
1、SQL> create directory dump_dir as 'd:\dump';
目录已创建。
2、执行完上述命令后,还要进入OS,在D盘上动手创建文件夹:DUMP
3、授予grant read,write on directory dump_dir权限给用户
3-1、给scott用户授予权限
SQL> grant read,write on directory dump_dir to scott;
授权成功。
3-2、给hr用户授予权限
SQL> grant read,write on directory dump_dir to hr;
授权成功。
alter user scott identified by rjxy;
alter user hr identified by rjxy;
5、调用EXPDP导出表
5-1、以scott用户登录数据库,导出scott用户的dept,emp 2个表,导出文件名为s_tab.dmp:
SQL> $expdp scott/rjxy directory=dump_dir dumpfile=s_tab.dmp tables=dept,emp;
5-2、以hr用户登录数据库,导出hr用户的regions,jobs 2个表,导出文件名为h_tab.dmp:
SQL> $expdp hr/rjxy directory=dump_dir dumpfile=h_tab.dmp tables=regions,jobs;
5-3、以system用户登录数据库,导出scott用户的emp、dept、salgrade、bonus 4个表,导出文件名为tab1.dmp:
SQL> $expdp system/rjxy directory=dump_dir dumpfile=tab1.dmp tables=scott.emp,scott.dept,scott.salgrade,scott.bonus;
5-4、以system用户登录数据库,导出hr用户的employees、departments、jobs、countries 4个表,
导出文件名为tab2.dmp:
SQL> $expdp system/rjxy directory=dump_dir dumpfile=tab2.dmp
tables=hr.employees,hr.departments,hr.jobs,hr.countries;
6、调用EXPDP导出方案
6-1、以scott用户登录数据库,导出scott用户(方案),导出文件名为scott.dmp:
SQL> $expdp scott/tiger directory=dump_dir dumpfile=scott.dmp schemas=scott;
6-2、以hr用户登录数据库,导出hr用户(方案),导出文件名为hr.dmp:
SQL> $expdp hr/rjxy directory=dump_dir dumpfile=hr.dmp schemas=hr;
6-3、以system用户登录数据库,导出system用户(方案),导出文件名为system.dmp:
SQL> $expdp system/rjxy directory=dump_dir dumpfile=system.dmp schemas=system;
7、调用EXPDP导出表空间
7-1、以system用户登录数据库,导出表空间system、sysaux,导出文件名为tablespace.dmp:
SQL> $expdp system/rjxy directory=dump_dir dumpfile=tablespace.dmp tablespaces=system,sysaux;
7-2、以system用户登录数据库,导出表空间example、users,导出文件名为tablespace1.dmp:
SQL> $expdp system/rjxy directory=dump_dir dumpfile=tablespace1.dmp tablespaces=example,users;
8、调用EXPDP导出数据库
8-1、以system用户登录数据库,导出数据库,导出文件名为db.dmp:
SQL> $expdp system/rjxy directory=dump_dir dumpfile=db.dmp full=y;
8-2、以sys用户登录数据库,导出数据库,导出文件名为db1.dmp:
SQL> $expdp directory=dump_dir dumpfile=db1.dmp full=y;
用户名:sys/rjxy as sysdba
二、调用IMPDP
1、调用IMPDP导入表
1-1、以scott用户登录数据库,导入scott用户的dept,emp 2个表,导入文件名为s_tab.dmp:
SQL> $impdp scott/tiger directory=dump_dir dumpfile=s_tab.dmp tables=dept,emp table_exists_action=replace;
1-2、以hr用户登录数据库,导入hr用户的regions,jobs 2个表,导入文件名为h_tab.dmp:
SQL> SQL> $impdp hr/rjxy directory=dump_dir dumpfile=h_tab.dmp tables=regions,jobs table_exists_action=replace;
1-3、以system用户登录数据库,将scott用户的emp,dept,salgrade,bonus 4个表
导入到HR用户中,导入文件名为tab1.dmp:
SQL> $impdp system/rjxy directory=dump_dir dumpfile=tab1.dmp tables=scott.emp,scott.dept,scott.salgrade,scott.bonus
remap_schema=scott:hr table_exists_action=replace;
1-4、查看HR用户的所有表
SQL> select table_name from dba_tables where owner='HR';
TABLE_NAME
------------------------------
BONUS
SALGRADE
DEPT
EMP
REGIONS
JOBS
LOCATIONS
DEPARTMENTS
EMPLOYEES
JOB_HISTORY
COUNTRIES
已选择11行。
2、调用impdp导入方案
2-1、以scott用户登录数据库,导入scott用户(方案),导入文件名为scott.dmp:
SQL> $impdp scott/rjxy directory=dump_dir dumpfile=scott.dmp schemas=scott table_exists_action=replace;
2-2、以hr用户登录数据库,导入hr用户(方案),导入文件名为hr.dmp:
SQL> $impdp hr/rjxy directory=dump_dir dumpfile=hr.dmp schemas=hr table_exists_action=replace;
2-4、以system用户登录数据库,导入system用户(方案),导入文件名为system.dmp:
SQL> $impdp system/rjxy directory=dump_dir dumpfile=system.dmp schemas=system table_exists_action=replace;
3、调用impdp导入表空间
3-1、以system用户登录数据库,导入表空间system、sysaux,导入文件名为tablespace.dmp:
SQL> $impdp system/rjxy directory=dump_dir dumpfile=tablespace.dmp tablespaces=system,sysaux table_exists_action=replace;
3-2、以system用户登录数据库,导入表空间example、users,导入文件名为tablespace1.dmp:
SQL> $impdp system/rjxy directory=dump_dir dumpfile=tablespace1.dmp tablespaces=example,users table_exists_action=replace;
4、调用impdp导入数据库
4-1、以system用户登录数据库,导入数据库,导入文件名为db.dmp:
SQL> $impdp system/rjxy directory=dump_dir dumpfile=db.dmp full=y;
4-2、以sys用户登录数据库,导入数据库,导入文件名为db1.dmp:
SQL> $impdp directory=dump_dir dumpfile=db1.dmp full=y;
用户名:sys/rjxy as sysdba
上一条:
下一条:
版权声明:
如果本站的资源使用了您的作品,请联系我们,我们会及时的注明
本站所有的资源均为免费自由下载,目的是让大家学习和交流
由于收集过程中几经转载,所以很多作品的原作者不详
如果您不愿在本站展示,请联系我们,我们会及时删除
相关评论
发表评论