ITPub博客

首页 > 数据库 > Oracle > exp / imp

exp / imp

原创 Oracle 作者:diashad 时间:2014-09-25 07:55:45 0 删除 编辑
exp / imp

查看帮助: exp help=y / imp help=y

a. 用户模式: 导出用户所有对象以及对象中的数据;
b. 表模式: 导出用户所有表或者指定的表;指定行
c. 整个数据库: 导出数据库中所有对象


1.交互模式:
	# 从交互模式中可以非常清晰的看出exp的功能
	
2.命令行模式:
	exp userid=scott/tiger tables=ob,emp file=/home/oracle/exp1.dmp buffer=100000 feedback=5000 log=/home/oracle/expob.log
	exp '/ as sysdba' tables=e file=c:\e.dmp log=e.log

	sqlplus scott/tiger
	drop table ob purge;

	命令行模式导入:
	imp userid=scott/tiger tables=ob file=/home/oracle/exp1.dmp buffer=100000 feedback=5000 log=/home/oracle/impob.log
	imp '/ as sysdba' tables=e file=c:\e.dmp log=e.log

	命令行模式的备份脚本,使用环境变量自动生成文件名
	~~~~vi /home/oracle/bk.sh~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	export ORACLE_HOME=/u01/oracle/10g
	export ORACLE_SID=vdon
	path=/home/oracle/expbak
	exp_file=`date '+%Y%m%d_%H%M%S'`
	sysdate=`date '+%Y%m%d'`
	mkdir -p $path/$sysdate/
	`$ORACLE_HOME/bin/exp scott/tiger file=$path/$sysdate/$exp_file\_ob.dmp log=$path/$sysdate/$exp_file\_ob.log tables=scott.ob`
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	chmod +x bk.sh
	./bk.sh

3.参数文件模式:
	创建exp需要的参数文件
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	tables=ob 
	file=/home/oracle/exp2.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expob.log

	创建imp需要的参数文件
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	tables=ob 
	file=/home/oracle/exp2.dmp 
	buffer=100000 
	feedback=5000 
	ignore=y       --不要随便使用,追加数据的选项,可以忽略建表错误
	log=/home/oracle/imp2.log

	调用exp & imp时使用parfile参数指定参数文件
	exp parfile=/home/oracle/exp.txt
	imp parfile=/home/oracle/imp.txt

exp备份的模式:
	1.表模式

	只导出表结构(元数据)不包含数据:
	导出时使用的参数文件
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	tables=ob
	rows=n		# expdp content=metadata_only
	file=/home/oracle/expmetadate_ob.dmp 
	log=/home/oracle/expmetadate_ob.log

	导入表结构时的参数文件:
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	full=y --将导出文件中的所有表全部导入数据库
	file=/home/oracle/expmetadate_ob.dmp 
	log=/home/oracle/expmetadate_ob.log

	导出单张表(既包含表结构又包含数据)
	导出时使用的参数文件
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	tables=ob
	file=/home/oracle/expob.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expob.log

	导入时使用的参数文件
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	tables=ob
	file=/home/oracle/expob.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/impob.log

	导出指定的数据:
	导出时使用的参数文件:
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	tables=ob
	query='where object_type=''TABLE'''	# 用在命令行模式时: exp scott/tiger TABLES=emp QUERY=\"WHERE job=\'SALESMAN\' and sal \<1600\"
	file=/home/oracle/expob.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expob.log

	删除表中数据:
	sqlplus scott/tiger
	delete ob where object_type='TABLE';
	commit;

	导入时使用的参数文件:
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	full=y --将导出文件中的所有数据都导入到数据库
	file=/home/oracle/expob.dmp 
	buffer=100000 
	feedback=5000 
	ignore=y
	log=/home/oracle/impob.log

	导出多张表
	导出时使用的参数文件:
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	tables=ob,dept,emp
	file=/home/oracle/exp1.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/exp1.log

	导入时使用的参数文件:
	导入一张表
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	tables=dept
	file=/home/oracle/exp1.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/imp1.log

	导入多张表
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	tables=dept,emp
	file=/home/oracle/exp1.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/imp1.log

	导入dmp文件中的所有表
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	full=y
	file=/home/oracle/exp1.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/imp1.log

	导入表数据时按buffer提交:
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	full=y
	file=/home/oracle/exp1.dmp 
	ignore=y --忽略建表错误
	commit=y --按buffer提交,默认风格是将表数据全部导入才提交
	buffer=100000 
	feedback=5000 
	log=/home/oracle/imp1.log

	导出时不使用压缩选项
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	tables=ob
	compress=n --创建表时初始范围继承表空间默认属性 
	file=/home/oracle/expob.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expob.log

	闪回导出(导出历史上某一时间点的数据状态,依赖undo老镜像):
	--/home/oracle/exp.txt--
	userid=system/oracle
	tables=scott.emp
	file=/home/oracle/expdept.dmp 
	flashback_time="to_timestamp('2011-03-28 15:25:06','yyyy-mm-dd hh24:mi:ss')"
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expdept.log

2.用户模式
	导出本方案所有数据:
	导出时使用的参数文件:
	--/home/oracle/exp.txt--
	userid=scott/tiger 
	owner=scott
	file=/home/oracle/expscott.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expscott.log

	导入方案所有数据:(需要先创建用户)
	drop user scott cascade;
	grant connect,resource to scott identified by tiger;

	导入时使用的参数文件:
	--/home/oracle/imp.txt--
	userid=scott/tiger 
	full=y
	file=/home/oracle/expscott.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/impscott.log

	跨用户导入数据(使用管理员权限):
	--/home/oracle/exp.txt--
	userid=system/oracle
	fromuser=scott
	touser=u1
	tables=dept,emp
	file=/home/oracle/expscott.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/impscott.log

3.表空间模式
	create tablespace demo datafile '/u1/oracle/oradata/updb/demo01.dbf' size 5m;
	create table scott.demo_data tablespace demo as select * from scott.emp;

	--/home/oracle/exp.txt--
	userid=system/oracle
	tablespaces=demo
	file=/home/oracle/expdemo.dmp 
	buffer=100000 
	feedback=5000 
	log=/home/oracle/expdemo.log


4.传输表空间模式
	create tablespace tbs18 datafile '/home/oracle/tbs18.dbf' size 5m;

	create user u1 identified by u1 default tablespace tbs18;
	grant connect,resource to u1;

	conn u1/u1
	create table t1 (id number(4),name varchar2(20));
	insert into t1 values (1,'ALVIN');
	commit;

	conn / as sysdba
	alter tablespace tbs18 read only;

	exp parfile=/home/oracle/exp.txt
	----------------------
	userid='sys/oracle as sysdba'
	tablespaces=tbs18
	transport_tablespace=y
	file=/home/oracle/trans_tbs18.dmp
	buffer=1000000
	log=/home/oracle/trans_tbs18.log

	将tbs18.dbf和trans_tbs18.dmp两个文件拷贝到远程节点
	创建U1用户:
	create user u1 identified by u1;
	grant connect,resource to u1;

	imp parfile=/home/oracleimp.txt
	-----------------------
	userid='sys/oracle as sysdba'
	file=/home/oracle/trans_data53.dmp
	tablespaces=tbs18
	transport_tablespace=y
	datafiles='/u1/oracle/oradata/updb/tbs18.dbf'
	log=/home/oracle/trans_data53.log

	conn / as sysdba
	alter tablespace tbs18 read write;

5.全库模式:不导sys的对象,但是会导出数据字典变化过的
	exp parfile=/home/oracle/exp.txt
	----------------------
	userid=system/oracle
	full=y
	filesize=50m
	file=(exp_full_1.dmp,exp_full_2.dmp)
	buffer=10000000
	feedback=10000
	log=exp_full.log

	imp parfile=/home/oracle/imp.txt
	-----------------------
	userid=system/oracle
	full=y
	filesize=50m
	file=(exp_full_1.dmp,exp_full_2.dmp)
	buffer=10000000
	feedback=10000
	log=imp_full.log

	
其它
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	将数据导入到指定的表空间:
	方法1:先在指定的表空间建表,使用ignore=y导入数据
	方法2: revoke unlimited tablespace from xxx;
			  fromuser touser
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	只列出导入内容而不导入数据
	imp show=y

	compress=y/n区别:compress=n,保留导出表的extents结构
	没有压缩:恢复的时候,插入数据,空间满后自动扩增
	有压缩:imp的时候,一次性把空间分配好 
	create table时initital 的参数区别


	SYS>select * from nls_database_parameters;
	字符集问题:Nexport NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1

	方法二:exp STATISTICS=none

	EXP-00091: Exporting questionable statistics.
	EXP-00091: Exporting questionable statistics.
	. . exporting table                           DEPT
																4 rows exported
	EXP-00091: Exporting questionable statistics.
	EXP-00091: Exporting questionable statistics.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/203348/viewspace-1280103/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: expdp / impdp
请登录后发表评论 登录
全部评论

注册时间:2011-08-08

  • 博文量
    86
  • 访问量
    472941