求教linux 下oracle数据的导入导出方法详细步骤 请教下linux如何导出 oracle 数据,最好有详细步骤...

\u6c42\u6559linux \u4e0boracle\u6570\u636e\u7684\u5bfc\u5165\u5bfc\u51fa\u65b9\u6cd5\u8be6\u7ec6\u6b65\u9aa4

\u4e00. \u5bfc\u51fa\u5de5\u5177 exp

1. \u5b83\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u4e00\u4e2a\u53ef\u6267\u884c\u7684\u6587\u4ef6 \u5b58\u653e\u76ee\u5f55/ORACLE_HOME/bin

exp\u5bfc\u51fa\u5de5\u5177\u5c06\u6570\u636e\u5e93\u4e2d\u6570\u636e\u5907\u4efd\u538b\u7f29\u6210\u4e00\u4e2a\u4e8c\u8fdb\u5236\u7cfb\u7edf\u6587\u4ef6.\u53ef\u4ee5\u5728\u4e0d\u540cOS\u95f4\u8fc1\u79fb

\u5b83\u6709\u4e09\u79cd\u6a21\u5f0f\uff1a
a. \u7528\u6237\u6a21\u5f0f\uff1a \u5bfc\u51fa\u7528\u6237\u6240\u6709\u5bf9\u8c61\u4ee5\u53ca\u5bf9\u8c61\u4e2d\u7684\u6570\u636e\uff1b
b. \u8868\u6a21\u5f0f\uff1a \u5bfc\u51fa\u7528\u6237\u6240\u6709\u8868\u6216\u8005\u6307\u5b9a\u7684\u8868\uff1b
c. \u6574\u4e2a\u6570\u636e\u5e93\uff1a \u5bfc\u51fa\u6570\u636e\u5e93\u4e2d\u6240\u6709\u5bf9\u8c61\u3002

2. \u5bfc\u51fa\u5de5\u5177exp\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u65b9\u5f0f\u7684\u4f7f\u7528\u7684\u4f8b\u5b50

$exp test/test123@appdb
Enter array fetch buffer size: 4096 > \u56de\u8f66
Export file: expdat.dmp > m.dmp \u751f\u6210\u5bfc\u51fa\u7684\u6587\u4ef6\u540d
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3
Export table data (yes/no): yes > \u56de\u8f66
Compress extents (yes/no): yes > \u56de\u8f66
Export done in ZHS16GBK character set and ZHS16GBK NCHAR character set
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > cmamenu \u8981\u5bfc\u51fa\u7684\u8868\u540d
. . exporting table CMAMENU 4336 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >\u8981\u5bfc\u51fa\u7684\u8868\u540dn
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > \u56de\u8f66
Export terminated successfully without warnings.

3. \u5bfc\u51fa\u5de5\u5177exp\u975e\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u65b9\u5f0f\u7684\u4f8b\u5b50

$exp scott/tiger tables=(emp,dept) file=/directory/scott.dmp grants=y

\u8bf4\u660e:\u628ascott\u7528\u6237\u91cc\u4e24\u4e2a\u8868emp,dept\u5bfc\u51fa\u5230\u6587\u4ef6/directory/scott.dmp

$exp scott/tiger tables=emp query=\"where job=\'salesman\' and sal\<1600\" file=/directory/scott2.dmp

\u8bf4\u660e:\u5728exp\u91cc\u9762\u52a0\u4e0a\u5bfc\u51faemp\u7684\u67e5\u8be2\u6761\u4ef6job='salesman' and sal<1600

(\u4f46\u6211\u4e2a\u4eba\u5f88\u5c11\u8fd9\u6837\u7528,\u8fd8\u662f\u628a\u6ee1\u8db3\u6761\u4ef6\u7684\u8bb0\u5f55\u751f\u6210\u4e34\u65f6\u8868\u540e,\u518dexp\u4f1a\u65b9\u4fbf\u4e00\u4e9b)

$exp parfile=username.par
file=/directory1/username_1.dmp,/directory1/username_2.dmp
filesize=2000M log=/directory2/username_exp.log

\u53c2\u6570\u6587\u4ef6username.par\u5185\u5bb9
userid=username/userpassword
buffer=8192000
compress=n
grants=y

\u8bf4\u660e:username.par\u4e3a\u5bfc\u51fa\u5de5\u5177exp\u7528\u7684\u53c2\u6570\u6587\u4ef6,\u91cc\u9762\u5177\u4f53\u53c2\u6570\u53ef\u4ee5\u6839\u636e\u9700\u8981\u53bb\u4fee\u6539

filesize\u6307\u5b9a\u751f\u6210\u7684\u4e8c\u8fdb\u5236\u5907\u4efd\u6587\u4ef6\u7684\u6700\u5927\u5b57\u8282\u6570

(\u53ef\u7528\u6765\u89e3\u51b3\u67d0\u4e9bOS\u4e0b2G\u7269\u7406\u6587\u4ef6\u7684\u9650\u5236\u53ca\u52a0\u5feb\u538b\u7f29\u901f\u5ea6\u548c\u65b9\u4fbf\u523b\u5386\u53f2\u6570\u636e\u5149\u76d8\u7b49)

\u4e8c.\u5bfc\u5165\u5de5\u5177 imp

1. \u5b83\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u4e00\u4e2a\u53ef\u6267\u884c\u7684\u6587\u4ef6 \u5b58\u653e\u76ee\u5f55/ORACLE_HOME/bin

imp\u5bfc\u5165\u5de5\u5177\u5c06EXP\u5f62\u6210\u7684\u4e8c\u8fdb\u5236\u7cfb\u7edf\u6587\u4ef6\u5bfc\u5165\u5230\u6570\u636e\u5e93\u4e2d.

\u5b83\u6709\u4e09\u79cd\u6a21\u5f0f\uff1a
a. \u7528\u6237\u6a21\u5f0f\uff1a \u5bfc\u51fa\u7528\u6237\u6240\u6709\u5bf9\u8c61\u4ee5\u53ca\u5bf9\u8c61\u4e2d\u7684\u6570\u636e\uff1b
b. \u8868\u6a21\u5f0f\uff1a \u5bfc\u51fa\u7528\u6237\u6240\u6709\u8868\u6216\u8005\u6307\u5b9a\u7684\u8868\uff1b
c. \u6574\u4e2a\u6570\u636e\u5e93\uff1a \u5bfc\u51fa\u6570\u636e\u5e93\u4e2d\u6240\u6709\u5bf9\u8c61\u3002

\u53ea\u6709\u62e5\u6709IMP_FULL_DATABASE\u548cDBA\u6743\u9650\u7684\u7528\u6237\u624d\u80fd\u505a\u6574\u4e2a\u6570\u636e\u5e93\u5bfc\u5165

imp\u6b65\u9aa4\uff1a
(1) create table (2) insert data (3) create index (4) create triggers,constraints

2.\u5bfc\u5165\u5de5\u5177imp\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u65b9\u5f0f\u7684\u4f8b\u5b50
$ imp
Import: Release 8.1.6.0.0 - Production on \u661f\u671f\u4e94 12\u6708 7 17:01:08 2001
(c) Copyright 1999 Oracle Corporation. All rights reserved.
\u7528\u6237\u540d: test
\u53e3\u4ee4:****
\u8fde\u63a5\u5230: Oracle8i Enterprise Edition Release 8.1.6.0.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
\u5bfc\u5165\u6587\u4ef6: expdat.dmp> /tmp/m.dmp
\u8f93\u5165\u63d2\u5165\u7f13\u51b2\u533a\u5927\u5c0f\uff08\u6700\u5c0f\u4e3a 8192 ) 30720>
\u7ecf\u7531\u5e38\u89c4\u8def\u5f84\u5bfc\u51fa\u7531EXPORT:V08.01.06\u521b\u5efa\u7684\u6587\u4ef6
\u8b66\u544a: \u6b64\u5bf9\u8c61\u7531 TEST \u5bfc\u51fa, \u800c\u4e0d\u662f\u5f53\u524d\u7528\u6237
\u5df2\u7ecf\u5b8c\u6210ZHS16GBK\u5b57\u7b26\u96c6\u548cZHS16GBK NCHAR \u5b57\u7b26\u96c6\u4e2d\u7684\u5bfc\u5165
\u53ea\u5217\u51fa\u5bfc\u5165\u6587\u4ef6\u7684\u5185\u5bb9(yes/no)\uff1ano>
\u7531\u4e8e\u5bf9\u8c61\u5df2\u5b58\u5728, \u5ffd\u7565\u521b\u5efa\u9519\u8bef(yes/no)\uff1ano> yes
\u5bfc\u5165\u6743\u9650(yes/no)\uff1ayes>
\u5bfc\u5165\u8868\u6570\u636e(yes/no)\uff1ayes>
\u5bfc\u5165\u6574\u4e2a\u5bfc\u51fa\u6587\u4ef6(yes/no)\uff1ano> yes
. \u6b63\u5728\u5c06TEST\u7684\u5bf9\u8c61\u5bfc\u5165\u5230 SCOTT
. . \u6b63\u5728\u5bfc\u5165\u8868 "CMAMENU" 4336\u884c\u88ab\u5bfc\u5165
\u6210\u529f\u7ec8\u6b62\u5bfc\u5165\uff0c\u4f46\u51fa\u73b0\u8b66\u544a\u3002

3.\u5bfc\u5165\u5de5\u5177imp\u975e\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u65b9\u5f0f\u7684\u4f8b\u5b50

$ imp system/manager fromuser=jones tables=(accts)
$ imp system/manager fromuser=scott tables=(emp,dept)
$ imp system/manager fromuser=scott touser=joe tables=emp
$ imp scott/tiger file = expdat.dmp full=y
$ imp scott/tiger file = /mnt1/t1.dmp show=n buffer=2048000 ignore=n
commit=y grants=y full=y log=/oracle_backup/log/imp_scott.log
$ imp system/manager parfile=params.dat
params.dat \u5185\u5bb9
file=dba.dmp show=n ignore=n grants=y fromuser=scott tables=(dept,emp)

4.\u5bfc\u5165\u5de5\u5177imp\u53ef\u80fd\u51fa\u73b0\u7684\u95ee\u9898

(1) \u6570\u636e\u5e93\u5bf9\u8c61\u5df2\u7ecf\u5b58\u5728
\u4e00\u822c\u60c5\u51b5, \u5bfc\u5165\u6570\u636e\u524d\u5e94\u8be5\u5f7b\u5e95\u5220\u9664\u76ee\u6807\u6570\u636e\u4e0b\u7684\u8868, \u5e8f\u5217, \u51fd\u6570/\u8fc7\u7a0b,\u89e6\u53d1\u5668\u7b49;
\u6570\u636e\u5e93\u5bf9\u8c61\u5df2\u7ecf\u5b58\u5728, \u6309\u7f3a\u7701\u7684imp\u53c2\u6570, \u5219\u4f1a\u5bfc\u5165\u5931\u8d25
\u5982\u679c\u7528\u4e86\u53c2\u6570ignore=y, \u4f1a\u628aexp\u6587\u4ef6\u5185\u7684\u6570\u636e\u5185\u5bb9\u5bfc\u5165
\u5982\u679c\u8868\u6709\u552f\u4e00\u5173\u952e\u5b57\u7684\u7ea6\u675f\u6761\u4ef6, \u4e0d\u5408\u6761\u4ef6\u5c06\u4e0d\u88ab\u5bfc\u5165
\u5982\u679c\u8868\u6ca1\u6709\u552f\u4e00\u5173\u952e\u5b57\u7684\u7ea6\u675f\u6761\u4ef6, \u5c06\u5f15\u8d77\u8bb0\u5f55\u91cd\u590d

(2) \u6570\u636e\u5e93\u5bf9\u8c61\u6709\u4e3b\u5916\u952e\u7ea6\u675f
\u4e0d\u7b26\u5408\u4e3b\u5916\u952e\u7ea6\u675f\u65f6, \u6570\u636e\u4f1a\u5bfc\u5165\u5931\u8d25
\u89e3\u51b3\u529e\u6cd5: \u5148\u5bfc\u5165\u4e3b\u8868, \u518d\u5bfc\u5165\u4f9d\u5b58\u8868
disable\u76ee\u6807\u5bfc\u5165\u5bf9\u8c61\u7684\u4e3b\u5916\u952e\u7ea6\u675f, \u5bfc\u5165\u6570\u636e\u540e, \u518denable\u5b83\u4eec
(3) \u6743\u9650\u4e0d\u591f
\u5982\u679c\u8981\u628aA\u7528\u6237\u7684\u6570\u636e\u5bfc\u5165B\u7528\u6237\u4e0b, A\u7528\u6237\u9700\u8981\u6709imp_full_database\u6743\u9650

(4) \u5bfc\u5165\u5927\u8868( \u5927\u4e8e80M ) \u65f6, \u5b58\u50a8\u5206\u914d\u5931\u8d25
\u9ed8\u8ba4\u7684EXP\u65f6, compress = Y, \u4e5f\u5c31\u662f\u628a\u6240\u6709\u7684\u6570\u636e\u538b\u7f29\u5728\u4e00\u4e2a\u6570\u636e\u5757\u4e0a.
\u5bfc\u5165\u65f6, \u5982\u679c\u4e0d\u5b58\u5728\u8fde\u7eed\u4e00\u4e2a\u5927\u6570\u636e\u5757, \u5219\u4f1a\u5bfc\u5165\u5931\u8d25.
\u5bfc\u51fa80M\u4ee5\u4e0a\u7684\u5927\u8868\u65f6, \u8bb0\u5f97compress= N, \u5219\u4e0d\u4f1a\u5f15\u8d77\u8fd9\u79cd\u9519\u8bef.

(5) imp\u548cexp\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u4e0d\u540c
\u5982\u679c\u5b57\u7b26\u96c6\u4e0d\u540c, \u5bfc\u5165\u4f1a\u5931\u8d25, \u53ef\u4ee5\u6539\u53d8unix\u73af\u5883\u53d8\u91cf\u6216\u8005NT\u6ce8\u518c\u8868\u91ccNLS_LANG\u76f8\u5173\u4fe1\u606f.
\u5bfc\u5165\u5b8c\u6210\u540e\u518d\u6539\u56de\u6765.

(6) imp\u548cexp\u7248\u672c\u4e0d\u80fd\u5f80\u4e0a\u517c\u5bb9
imp\u53ef\u4ee5\u6210\u529f\u5bfc\u5165\u4f4e\u7248\u672cexp\u751f\u6210\u7684\u6587\u4ef6, \u4e0d\u80fd\u5bfc\u5165\u9ad8\u7248\u672cexp\u751f\u6210\u7684\u6587\u4ef6
\u6839\u636e\u60c5\u51b5\u6211\u4eec\u53ef\u4ee5\u7528
$ imp username/password@connect_string
\u8bf4\u660e: connect_string \u662f\u5728/ORACLE_HOME/network/admin/tnsnames.ora
\u5b9a\u4e49\u7684\u672c\u5730\u6216\u8005\u8fdc\u7aef\u6570\u636e\u5e93\u7684\u540d\u79f0
\u6ce8\u610f\u4e8b\u9879:
UNIX: /etc/hosts \u8981\u5b9a\u4e49\u672c\u5730\u6216\u8005\u8fdc\u7aef\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d
win98: windows\hosts \u548cIP\u5730\u5740\u7684\u5bf9\u5e94\u5173\u7cfb
win2000: winnt\system32\drivers\etc\hosts

su - oracle
df -k \u67e5\u770b\u4e0boracle\u6240\u5728\u78c1\u76d8\u7a7a\u95f4\u5927\u5c0f,\u8981\u9884\u4f30\u4e0b\u78c1\u76d8\u7a7a\u95f4\u662f\u5426\u8db3\u591f
\u76f4\u63a5\u6267\u884c\u547d\u4ee4(\u4e0d\u7528\u8fdbsqlplus\u547d\u4ee4\u4e0b):
\u5bfc\u51fa: exp dbuser/passwd@servicename owner=dbuser rows=y compress=n buffer=65536 feedback=100000 file=/path/exp_db.dmp
\u5bfc\u5165: imp dbnewuser/passwd@servicename fromuser=dbolduser touser=dbnewuser rows=y commit=y buffer=65536 feedback=100000 ignore=y volsize=0 file=/path/exp_db.dmp

求教linux 下oracle数据的导入导出方法详细步骤
一. 导出工具 exp

1. 它是操作系统下一个可执行的文件 存放目录/ORACLE_HOME/bin

exp导出工具将数据库中数据备份压缩成一个二进制系统文件.可以在不同OS间迁移

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

2. 导出工具exp交互式命令行方式的使用的例子

$exp test/test123@appdb
Enter array fetch buffer size: 4096 > 回车
Export file: expdat.dmp > m.dmp 生成导出的文件名
(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > 3
Export table data (yes/no): yes > 回车
Compress extents (yes/no): yes > 回车
Export done in ZHS16GBK character set and ZHS16GBK NCHAR character set
About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > cmamenu 要导出的表名
. . exporting table CMAMENU 4336 rows exported
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >要导出的表名n
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > 回车
Export terminated successfully without warnings.

3. 导出工具exp非交互式命令行方式的例子

$exp scott/tiger tables=(emp,dept) file=/directory/scott.dmp grants=y

说明:把scott用户里两个表emp,dept导出到文件/directory/scott.dmp

$exp scott/tiger tables=emp query=\"where job=\'salesman\' and sal\<1600\" file=/directory/scott2.dmp

说明:在exp里面加上导出emp的查询条件job='salesman' and sal<1600

(但我个人很少这样用,还是把满足条件的记录生成临时表后,再exp会方便一些)

$exp parfile=username.par
file=/directory1/username_1.dmp,/directory1/username_2.dmp
filesize=2000M log=/directory2/username_exp.log

参数文件username.par内容
userid=username/userpassword
buffer=8192000
compress=n
grants=y

说明:username.par为导出工具exp用的参数文件,里面具体参数可以根据需要去修改

filesize指定生成的二进制备份文件的最大字节数

(可用来解决某些OS下2G物理文件的限制及加快压缩速度和方便刻历史数据光盘等)

二.导入工具 imp

1. 它是操作系统下一个可执行的文件 存放目录/ORACLE_HOME/bin

imp导入工具将EXP形成的二进制系统文件导入到数据库中.

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

只有拥有IMP_FULL_DATABASE和DBA权限的用户才能做整个数据库导入

imp步骤:
(1) create table (2) insert data (3) create index (4) create triggers,constraints

2.导入工具imp交互式命令行方式的例子
$ imp
Import: Release 8.1.6.0.0 - Production on 星期五 12月 7 17:01:08 2001
(c) Copyright 1999 Oracle Corporation. All rights reserved.
用户名: test
口令:****
连接到: Oracle8i Enterprise Edition Release 8.1.6.0.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.6.0.0 - Production
导入文件: expdat.dmp> /tmp/m.dmp
输入插入缓冲区大小(最小为 8192 ) 30720>
经由常规路径导出由EXPORT:V08.01.06创建的文件
警告: 此对象由 TEST 导出, 而不是当前用户
已经完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的导入
只列出导入文件的内容(yes/no):no>
由于对象已存在, 忽略创建错误(yes/no):no> yes
导入权限(yes/no):yes>
导入表数据(yes/no):yes>
导入整个导出文件(yes/no):no> yes
. 正在将TEST的对象导入到 SCOTT
. . 正在导入表 "CMAMENU" 4336行被导入
成功终止导入,但出现警告。

3.导入工具imp非交互式命令行方式的例子

$ imp system/manager fromuser=jones tables=(accts)
$ imp system/manager fromuser=scott tables=(emp,dept)
$ imp system/manager fromuser=scott touser=joe tables=emp
$ imp scott/tiger file = expdat.dmp full=y
$ imp scott/tiger file = /mnt1/t1.dmp show=n buffer=2048000 ignore=n
commit=y grants=y full=y log=/oracle_backup/log/imp_scott.log
$ imp system/manager parfile=params.dat
params.dat 内容
file=dba.dmp show=n ignore=n grants=y fromuser=scott tables=(dept,emp)

4.导入工具imp可能出现的问题

(1) 数据库对象已经存在
一般情况, 导入数据前应该彻底删除目标数据下的表, 序列, 函数/过程,触发器等;
数据库对象已经存在, 按缺省的imp参数, 则会导入失败
如果用了参数ignore=y, 会把exp文件内的数据内容导入
如果表有唯一关键字的约束条件, 不合条件将不被导入
如果表没有唯一关键字的约束条件, 将引起记录重复

(2) 数据库对象有主外键约束
不符合主外键约束时, 数据会导入失败
解决办法: 先导入主表, 再导入依存表
disable目标导入对象的主外键约束, 导入数据后, 再enable它们
(3) 权限不够
如果要把A用户的数据导入B用户下, A用户需要有imp_full_database权限

(4) 导入大表( 大于80M ) 时, 存储分配失败
默认的EXP时, compress = Y, 也就是把所有的数据压缩在一个数据块上.
导入时, 如果不存在连续一个大数据块, 则会导入失败.
导出80M以上的大表时, 记得compress= N, 则不会引起这种错误.

(5) imp和exp使用的字符集不同
如果字符集不同, 导入会失败, 可以改变unix环境变量或者NT注册表里NLS_LANG相关信息.
导入完成后再改回来.

(6) imp和exp版本不能往上兼容
imp可以成功导入低版本exp生成的文件, 不能导入高版本exp生成的文件
根据情况我们可以用
$ imp username/password@connect_string
说明: connect_string 是在/ORACLE_HOME/network/admin/tnsnames.ora
定义的本地或者远端数据库的名称
注意事项:
UNIX: /etc/hosts 要定义本地或者远端数据库服务器的主机名
win98: windows\hosts 和IP地址的对应关系

win2000: winnt\system32\drivers\etc\hosts

扩展阅读:javascript入门 ... 在线linux网站 ... oracle linux ... linux ps grep ... linux wc ... linux mount ... linux chmod 777 ... linux head ... linux mkdir ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网