本篇测试在windows下使用expdp命令导出oracle数据库中SCOTT用户所有表,并创建一个新的表空间和用户,使用impdp命令将数据导入到此用户下。
测试环境:
OS: Windows7_X64 旗舰版
DB: Oracle11gR2_X64
1
2
OS:Windows7_X64旗舰版
DB:Oracle11gR2_X64
首先我们启用SCOTT用户(为SCOTT用户解锁并设置密码):
ALTER USER SCOTT ACCOUNT UNLOCK;
ALTER USER SCOTT IDENTIFIED BY SCOTT;
1
2
ALTERUSERSCOTTACCOUNTUNLOCK;
ALTERUSERSCOTTIDENTIFIEDBYSCOTT;
一、使用expdp命令导出SCOTT用户所有表
1.1、在windows系统上创建一个目录,用于存放导出的dmp文件
例如:我在C盘创建了C:\app\dump_dir目录
1.2、在oracle中创建一个directory(目录和刚才windows创建路径要一致,别名为dump_dir),并授权读写目录权限给到SCOTT用户
create directory dump_dir as 'C:\app\dump_dir';
grant read,write on directory dump_dir TO SCOTT;
1
2
createdirectorydump_diras'C:\app\dump_dir';
grantread,writeondirectorydump_dirTOSCOTT;
查询创建好的目录:
select * from dba_directories;
1
select *fromdba_directories;
1.3、查询下SCOTT用户的所有表和视图
select * from all_tab_comments where owner='SCOTT';
1
select *fromall_tab_commentswhereowner='SCOTT';
1.4、使用expdp导出SCOTT用户所有表
C:\Users\ZCY>expdp SCOTT/SCOTT DIRECTORY=DUMP_DIR schemas=SCOTT DUMPFILE=scott_20181125.dmp
Export: Release 11.2.0.1.0 - Production on 星期日 11月 25 17:34:00 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SCOTT"."SYS_EXPORT_SCHEMA_01": SCOTT/******** DIRECTORY=DUMP_DIR schemas=SCOTT DUMPFILE=scott_20181125.dmp
正在使用 BLOCKS 方法进行估计...