Oracle数据备份,dmp导入导出

以oracle11g为例,今天整理了一下数据库的导入导出、创建删除命令,包括数据泵的导入导出,现将操作及语句记录下来。

1、用dba登陆oracle,创建一个名为test_space的表空间,首先建好路径

CREATE TABLESPACE test_space
DATAFILE 'D:\app\Administrator\oradata\orcl\test_space.dbf' SIZE 10M AUTOEXTEND ON NEXT 1M;

2、创建用户test_user1,指定默认的表空间是test_space,密码是test_pwd1,并授予权限

CREATE USER test_user1 IDENTIFIED BY test_pwd1 DEFAULT TABLESPACE test_space;
GRANT CONNECT,RESOURCE,dba TO test_user1;
REVOKE UNLIMITED TABLESPACE FROM test_user1;
ALTER USER test_user1 QUOTA UNLIMITED ON test_space;


3、导出
在cmd命令下执行
exp test_user1/test_pwd1@orcl file=D:\exp_text_db.dmp log=D:\exp_text_db.log

数据库在局域网服务器上
exp test_user1/[email protected]/orcl file=D:\exp_text_db.dmp log=D:\exp_text_db.log

单独导出test_user_info表
exp test_user1/test_pwd1@orcl file=D:\exp_text_db.dmp log=D:\exp_text_db.log tables=test_user_info

4、导入
将导出备份导入到名为test_user2的用户,密码为test_pwd2,需要先创建test_user2用户
在cmd命令下执行
方法一、用户模式导入:

imp test_user2/test_pwd2@orcl fromuser=test_user1 touser=test_user2 file=d:\exp_text_db.dmp log=e:\imp_text_db.log

方法二、完全导入:
imp test_user2/test_pwd2@orcl full=y buffer=5400000 file=d:\exp_text_db.dmp ignore=y;
(如果想导入原用户,可以重新创建test_user1,将以上命令test_user2换成test_user1即可)

5、删除用户
drop user test_user1 cascade;

6、删除表空间
drop tablespace test_space including contents and datafiles;

/********************数据泵导入导出********************/
从Oracle10g开始推出的数据泵EXPDP/IMPDP,数据泵只能用于服务器端,最大的优点之一就是效率,确实比EXP/IMP有了一个量级的提升,这里我们简单介绍一下
1、数据泵导出
expdp test_user1/test_pwd1@orcl dumpfile=exp_text_db.dmp log=exp_text_db.log
(导出的dmp文件默认路径:D:\oracle安装目录\admin\orcl\dpdump)

导出时排出某些表

windows环境

expdp test_user1/test_pwd1@orcl dumpfile=exp_text_db.dmpexclude=TABLE:\"IN ('TABLENAME1', 'TABLENAME2')\"

linux环境

expdp test_user1/test_pwd1@orcl dumpfile=exp_text_db.dmp log=gacwp_201603271201.log exclude=TABLE:\"IN \'TABLENAME1\',\'TABLENAME2\'\'TABLENAME1\',\'TABLENAME2\'\"

2、数据泵导入
使用管理员登录,会自动按导出的用户名建新用户,无需建立用户,但表空间要事件创建
impdp system/system@orcl dumpfile=exp_text_db.dmp schemas=test_user1
(导入文件要在默认路径中)

如果导入时想更换用户名
impdp system/system@orcl dumpfile=exp_text_db.dmp remap_schema=test_user1:test_user2

导入整个数据库
impdp system/system@orcl dumpfile=exp_text_db.dmp full=y

更多内容,来公号【只差一个技术】,总有一个适合你!

猜你喜欢

转载自blog.csdn.net/weixin_52578018/article/details/110038141