oracle 对数据库的导出、导入操作用exp、imp命令实现:exp命令用于把数据从远程数据库服务器导出至本地生成dmp文件,imp命令用于把本地的数据库dmp文件从本地导入到远程的Oracle数据库中。
导出:
数据库TEST,用户名:system,密码:manager
1.将数据库完全导出到D:\TEST.dmp中
exp system/manager@TEST file=D:\TEST.dmp full=y
2.将数据库中sys1用户与sys2用户的表导出至D:\TEST.dmp中
exp system/manager@TEST file=D:\TEST.dmp owner=(sys1,sys2)
3.将数据库中的表tab1,tab2 导出至D:\TEST.dmp中
exp system/manager@TEST file=D:\TEST.dmp tables=(tab1,tab2)
4.将数据库中的表tab1中的字段name值里有"小"字的数据导出
exp system/manager@TEST file= D:\TEST.dmp tables=(tab1) query=” where name like '%小%’ ”
5.导出后对dmp文件进行压缩,在命令后面加上compress=y
exp system/manager@TEST file=D:\TEST.dmp tables=(tab1,tab2) compress=y
导入:
数据库TEST,用户名:system,密码:manager 数据文件:D:\TEST.dmp
1.将文件中数据导入至数据库
imp system/manager@TEST file= D:\TEST.dmp
(如果有的表在数据库中已经存在,导入时然后它就报错,对该表就不进行导入,这时候需要加上ignore=y)
2.文件中的数据导入数据库,如果数据库已存在该表,则不再导入
imp system/manager@TEST file= D:\TEST.dmp full=y ignore=y
3.将D:\TEST.dmp中的表table1导入
imp system/manager@TEST file= D:\TEST.dmp tables=(table1)
4. 将用户user1所属的数据导入时所属权转给用户user2
imp system/manager file= D:\TEST.dmp fromuser=user1 touser=user2