《oracle每日一练》oralce数据库的导入导出

今天尝试了数据库的导出,直接在命令行里面使用了导出指令:

exp uname/pwd@127.0.0.1:1521/orcl  file='xx.dmp'  

出现的问题:

直接@tnsnames里面配的网络服务名 exp uname/pwd@test  是报错;

改为exp uname/pwd@127.0.0.1:1521/orcl (test在tnsnames文件里面对应的IP地址加上实例名127.0.0.1:1521/orcl时,导出成功)

参考帖子参考帖子2,概念搞错了
@后面跟的不是实例名,只是在tnsnames里面配的网络服务名

导入导出常见的命令,参考帖子

数据库导出功能:

1 将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp中
exp system/manager@TEST file=d:daochu.dmp full=y
2 将数据库中system用户与sys用户的表导出
exp system/manager@TEST file=d:daochu.dmp owner=(system,sys)
3 将数据库中的表table1 、table2导出
exp system/manager@TEST file=d:daochu.dmp tables=(table1,table2)
4 将数据库中的表table1中的字段filed1以"00"打头的数据导出
exp system/manager@TEST file=d:daochu.dmp tables=(table1) query=" where filed1 like '00%'"

数据的导入
1 将D:daochu.dmp 中的数据导入 TEST数据库中。
imp system/manager@TEST file=d:daochu.dmp ignore=y
上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
在后面加上 ignore=y 就可以了。
2 将d:daochu.dmp中的表table1 导入
imp system/manager@TEST file=d:daochu.dmp tables=(table1)

3.更多示例

【示例】

1、【全库模式】将备份数据库文件中的数据导入数据库orcl中,用户名scott密码scott,数据文件路径D:/orcl/scott.dmp,日志文件路径D:/orcl/scott.log

imp scott/scott@orcl file = D:/orcl/scott.dmp log =D:/orcl/scott.log full = y ignore = y

2、【表模式】将备份数据库文件中的表emp、dept数据导入数据库orcl中,用户名scott密码scott,数据文件路径D:/orcl/scott.dmp

imp scott/scott@orcl file = D:/orcl/scott.dmp log =D:/orcl/scott.log ignore = y tables = (emp,dept)

另外,如果导出时使用了表模式,导入时要导入所有表数据,则也可以使用full = y,如:

imp scott/scott@orcl file = D:/orcl/scott_empdept.dmp ignore= y full = y

3、【用户模式】备份数据文件中存在ng_lxj1、ng_lxj2两用户数据,数据文件路径D:/orcltest/ng_lxj_user.dmp

将ng_lxj1的数据导入到ng_lxj中:

imp system/manager@243 file = D:/orcltest/ng_lxj_user.dmpfromuser = ng_lxj1 touser = ng_lxj

将ng_lxj1和ng_lxj2的数据均导入到ng_lxj中:

imp system/manager@243 file = D:/orcltest/ng_lxj_user.dmpfromuser = (ng_lxj1,ng_lxj2) touser = (ng_lxj,ng_lxj)

注意ng_lxj要写两遍与之前的对应,若仅写一个,Oracle会默认没得到对应的将导入到本用户下,如:

imp system/manager@243 file = D:/orcltest/ng_lxj_user.dmpfromuser = (ng_lxj1,ng_lxj2)

该命令将从ng_lxj1导入ng_lxj1,ng_lxj2导入ng_lxj2

将ng_lxj1的数据分别导入ng_lxj1和ng_lxj2两个用户:

不能写成imp system/manager@243 file = D:/orcltest/ng_lxj_user.dmpfromuser = (ng_lxj1,ng_lxj1) touser = (ng_lxj1,ng_lxj2)

否则会报错:

IMP-00034: 警告: 在导出文件中未找到 FromUser "NG_LXJ1"

猜测:Oracle将数据文件抽取到缓存区,一旦使用过就会进行清除。

所以,一个用户导向两个用户需要分开写两条命令语句。

将ng_lxj1用户下的t1表的数据导入ng_lxj2用户中:

imp system/manager@243 file = D:/orcltest/ng_lxj_user.dmpfromuser = ng_lxj1 touser = ng_lxj2 tables = t1

4、从备份数据文件中,仅导入建表语句而不导入数据记录,文件路径D:/orcl/scott.dmp

imp scott/scott@orcl file = D:/orcl/scott.dmp full = yignore = y rows = n

5、使用参数文件

imp system/manager@243 parfile=bible_tables.par

bible_tables.par参数文件:

file = D:/orcltest/ng_lxj_user.dmp fromuser = ng_lxj1touser = ng_lxj

原文地址:https://www.cnblogs.com/abc8023/p/5333184.html