oracle数据导出以及导入

导出

1.服务器上mkdir创建一个真实目录/home/oracle/dump

2.sqlplus /nolog

3.conn /as sysdba;

4.SQL> create directory data_dir as '/home/oracle/dump';

5.检查是否创建成功

select * from dba_directories;

6.用管理员用户给刚刚创建的虚拟目录赋权限

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

7.exit退出sql命令窗口执行导出动作

有五种导出方式:

    第一种:“full=y”,全量导出数据库;

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

    第二种:schemas按用户导出;

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

    第三种:按表空间导出;

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

    第四种:导出表;

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

    第五种:按查询条件导;

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

导入

首选切换数据库
export ORACLE_SID=bj;

然后sys连接数据库按照以下步骤操作:
1.创建临时表空间
create temporary tablespace TEMP_CPMDB_01 TEMPFILE '/u01/oradata/bj/tablespace/TEMP_CPMDB_01.DBF' size 256M autoextend on next 32M maxsize 2048m extent management local;
2.设置临时表空间为默认表空间
alter DATABASE default temporary tablespace TEMP_CPMDB_01;
3.创建表空间
create tablespace TSP_CPM logging datafile '/u01/oradata/bj/tablespace/TSP_CPM.DBF' size 3072M autoextend on next 32M maxsize unlimited extent management local;
4.创建用户
create user cpm identified by cpm account unlock default tablespace TSP_CPM TEMPORARY TABLESPACE TEMP_CPMDB_01;
5.授权
grant connect,resource to cpm;
grant dba to cpm;
6.创建目录
create directory imp_dir as '/tmp/importdata';
7.quit后导入数据
impdp cpm/cpm directory=imp_dir dumpfile=expdp_cpmdb_20170922.dmp logfile=impdp.log table_exists_action=replace;

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

    第一种:“full=y”,全量导入数据库;

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

    第二种:同名用户导入,从用户A导入到用户A;

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

    第三种:①从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

    第四种:导入表空间;

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

    第五种:追加数据;

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

posted on 2018-12-12 11:46  砌码匠人  阅读(278)  评论(0编辑  收藏  举报

导航