Orcale 备份与还原数据库

2014-11-24 18:31:38 · 作者: · 浏览: 0

Orcale 数据库备份数据的命令用exp.exe,还原数据库命令imp.exe


一、备份数据库——exp


格式:exp 用户名/密码@数据库 owner=拥有者 file=C:\xxx\xxx.dmp


eg1、数据库TEST完全导出,用户名:test, 密码:test,拥有者:tb_test 导出到D:\daochu.dmp中


exp test/test@TEST owner=tb_test file=d:\daochu.dmp


第二步:exp test/test@TEST owner=tb_test file=d:\daochu.dmp


eg2、将数据库中的表test中的字段filed1以"00"开头的数据导出,用户名:test, 密码:test


exp test/test@TEST file=d:\daochu.dmp tables=(test)query="where filed1 like '00%'"


注:可以在命令后面 加上 compress=y 来实现 文件压缩


二、还原数据库——imp


格式:imp 用户名/密码@数据库 full=y file=备份文件路径 ignore=y log=日志文件路径


eg 1、将D:\daochu.dmp文件还原到tb_test数据库中,用户名:test, 密码:test,日志文件放在D:/log.txt 中


第一步:进入到 oracle 安装目录下的bin目录下;


第二步:imp system/manager@tb_test full = y file="d:\back.dmp" ignore=y log=d:\log.txt


eg2、将d:\daochu.dmp中的表table1 导入到tb_test数据库中


imp system/manager@tb_test file=d:\daochu.dmp tables=(table1)


注:如何没有以前的表记录的话,有可能要出现重复数据,可以通过以下方式解决


首先,删除用户(本人用的test):DROP USER test CASCADE


其次,新建用户(test)


create user test identified by test


default tablespace test_data


temporary tablespace test_temp


quota unlimited on test_data


account unlock;


然后,给新建用户授权 GRANT CONNECT,DBA, RESOURCE TO test;


最后,执行导入数据命令。