oracle数据库导入导出

 oracle定义的时候可定义多个实例,一个实例中可以包含多个表空间,一般一个表空间可以对应多个用户。

oracle数据库导入导出

 

oracle数据库导出步骤:

#dba用户登录

> sqlplus /nolog

SQL> conn / as sysdba

#先创建一个放导入的dmp的路径,用户指定导出的数据库文件放置的位置

create directory dmp_file as 'E:/oracle_install/dmp';

#再推出sql模式,使用expdp命令导出对应表空间数据

expdp out_test/[email protected] directory=dmp_file dumpfile=out_test-xxxx.dmp logfile=out_test-xxxx.log

oracle数据库导入步骤:

#1,创建IMPORT_TEMP临时空间

create temporary tablespace IMPORT_TEMP tempfile 'E:/oracle_install/dbf/IMPORT_TEMP.dbf' size 100m reuse autoextend on next 20m maxsize unlimited;

#2,创建IMPORT 空间

create tablespace IMPORT datafile 'E:/oracle_install/dbf/IMPORT.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

#3,创建import 为用户,密码为import 且赋予IMPORT,IMPORT_TEMP 空间权限

create user import  identified by import  default tablespace IMPORT temporary tablespace IMPORT_TEMP ;

#4,给import  赋予权限

grant dba to import ;

grant connect,resource to import ;

grant select any table to import ;

grant delete any table to import ;

grant update any table to import ;

grant insert any table to import ;

#5,创建导入文件放置路径

SQL> create directory import_file as'f:/oracle_install/import_file ';

#6,将dmp文件路径读写权限赋予import用户

Grant read,write on directory dmp_dir to import ;

#7,退出sql模式导入数据库数据

directory=dmp文件放置的路径,对应第5步

dumpfile=dmp文件名称

remap_schema=导出空间用户:需要导入用户

remap_tablespace=导出的表空间名:导入的表空间名

logfile= 导入的日志名称,可用于查看导入时是否存在错误

transform=在数据泵导出导入时会产生大量的归档,可能比文件本身都大(oracle数据库 11g环境),

oracle 12c新加了transform参数可以禁用归档,只会产生少量的归档

impdp import/import  directory=import_file dumpfile=out_test-xxxx.dmp remap_tablespace=OUT:IMPORT remap_schema=out_test:import logfile=Import_xxxx.log transform=segment_attributes:n

【注意事项】

1,导入时需要知道原来数据库的表空间名称和用户名

2,导出数据库和导入数据库最好是同一个版本,不然容易导入报错失败,【如10版本11版本之间,11版本的企业版和标准版之间】

3,导入导出最好都带日志,方便跟踪导入导出存在的问题