Oracle:导入导出

来源:互联网 发布:json在线美化 编辑:程序博客网 时间:2024/06/03 20:46

Oracle数据库的导入和导出笔记总结:

在dos下运营oracle自带的exp.exe和imp.exe这个路径下、自己也可以设置环境变量……
自己:D:\MyOracle\product\11.2.0\dbhome_1\BIN
可以跳转到这个目录下运行 exp help =y;来查看其具体参数都有哪些:

和两种导出方式
第一种: exp scott/qian :给据提示一步一步往下输入yes/no操作
第二种: exp keyword = valuse的形式,也就是下文要讲述的内容;

导出:
主要包括三个方面:导出表、导出方案、导出数据库;
使用的命令即命令参数:
命令:exp
常用参数:
userid:用于指定执行导出操作的用户名、密码、和数据库字符串
tables:用于指定执行导出操作的表;
rows: 用于指定执行导出操作是否要导出表中的数据;
owner: 用于指定执行导出操作的方案
full=y:用于指定导出操作的数据库
inctype:用于指定执行导出操作的增量形式,如果指定第二次会在第一次
备份的基础上值增加内容有变更的部分,速度相对快点
file: 指定导出文件的名:要写绝对路径;相对就保存在默认盘文件中;
query:主要是导出合适条件的数据(select语句)。使用该参数时,需要注意对所有操作系统
保留字符都要使用转义符号。若有括号()也需要转义:
或者:我们可以使用exp的PARFILE参数避免query内容的繁琐转义问题
compress: 用于压缩数据;

导出表:table
导出自己的表:
1.导出表结构:
exp userid=scott/qia@ORCL tables =(emp,dept) file=f:\table.dmp rows =n;
2.导出表中的数据:
exp userid=scott/qia@ORCL tables=emp file=f:\emp.dmp query=\”where rownum<10\”
3.导出整个表(结构+数据)
exp userid=scott/qia@ORCL tables =(emp,dept) file=f:\table.dmp;
使用直接导出方式当表的数据特别大时可以用这种方式较快:
exp userid=scott/qia@ORCL tables=emp file=f:\emp.dmp direct=y;
4.导出指定行的表
exp zxcc.par userid=scott/qia@ORCL tables=emp file=f:\emp.dmp
query=”where dt_time=to_date(‘2010-06-25’,’yyyy-mm-dd’)”
导出其他用户方案的表:需要dba的权限
exp userid=system/qia@ORCL tables=(scott.emp) file =f:\table.dmp;

导出方案:owner
导出自己的方案:
exp scott/qia@ORCL owner=scott file=f:\scott.dmp;
导出其它方案:如果用户要导出其它方案,则需要dba的权限
exp system/qia@ORCL owner=(system,scott) file=f:\syssco.dmp compress=y;

导出数据库:full=y
导出数据库上所有的方案必须有dba的权限
exp userid=syetem/qia@ORCL full=y file=orcl.dmp inctype=complete compress=y;

导入:导入表、导入方案、导入数据库
命令:imp
参数:
userid:
tables:
fromuser:用于指定源用户
touser:用于指定目标用户
file:
full =y:执行导入整个文件
inctype
rows:指定是否导入表行(数据)
ignore:如果表存在只导入数据
导入表
导入自己的表:
imp userid=scott/qia@ORCL tables=(emp) file= f:\emp.dmp
导入表到气他用户:
imp userid=system/qia@ORCL tables=(emp) file= f:\emp.dmp touser =scott;
导入表的结构:
imp userid=scott/qia@ORCL tables=(emp) file=f:\emp.dmp rows =n;
导入数据:当表的结构已经存在了;
imp userid=scott/qia@ORCL tables=(emp) file=f:\emp.dmp ignore =y;
导入方案:
导入自身方案:
imp userid=scott/qia file=f:\scott.dmp;
导入其他用户的方案:需具备dba权限
imp userid=system/qia file=f:\scott.dmp fromuser=system tousr=scott;
导入数据库:
imp userid=system/qia file=f:\orcl.dmp full=y;

第二种方式:
一下是自己掏币下载的一个资料说的还算可以吧;
在oracle中,使用EXP程序导出数据到文件进行备份, 而使用IMP就可以进行恢复。

EXP可以导出一个数据库, 也可以指定导出数据库的某个对象相关信息,


下面开始进行备份: (备份学生表里的全部数据)

[oracle@localhost ~]$ exp scott/tiger <- 这里输入账号

Enter array fetch buffer size: 4096 > 4096 <-这里是缓冲区大小, 默认4096

Export file: expdat.dmp > mydata.dmp <-输入备份文件名字,默认名字expdat.dmp

(2)U(sers), or (3)T(ables): (2)U > T <- 因为我要备份表,所以选择T

Export table data (yes/no): yes > yes <- 是否导出表中的数据

Compress extents (yes/no): yes > yes <- 是否对数据进行压缩

Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified tables via Conventional Path …
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > xue_sheng <-输入备份的表名字

. . exporting table XUE_SHENG 2 rows exported <-导出提示信息
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > <- 退出就直接回车

Export terminated successfully without warnings.
[oracle@localhost ~]$

如果刚才没有指定备份文件的具体路径,备份文件mydata.dmp就会在当前目录下
[oracle@localhost ~]$ ls my*
mydata.dmp

=======================================

先把xue_sheng 表的数据全部删除

下面使用 IMP 进行数据恢复

[oracle@localhost ~]$ imp scott/tiger

Import data only (yes/no): no > yes

Import file: expdat.dmp > mydata.dmp

Enter insert buffer size (minimum is 8192) 30720>

Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no >

Ignore create error due to object existence (yes/no): no >

Import grants (yes/no): yes >

Import table data (yes/no): yes >

Import entire export file (yes/no): no > yes

. importing SCOTT’s objects into SCOTT
. . importing table “XUE_SHENG” 2 rows imported
Import terminated successfully with warnings.
[oracle@localhost ~]$


0 0
原创粉丝点击