1、SQL create directory dump_dir as /u01/app/oracle/admin/lsmesdb/dpdump;Directory created.SQL grant read,write on directory dump_dir to system;Grant succeeded.創建使用者create user test identified by test;授權GRANT CONNECT TO TEST;GRANT EXP_FULL_DATABASE TO TEST;GRANT IMP_FULL_DATABASE TO TEST;GRANT DBA TO T
2、EST1.導出整個數據庫exp test/testlinshine file=d:dumplinshine.dmp full=y2.導出特定的表exp test/testlinshine tables=color_admin.emp,color.dept file=mytable.dmp3.導出特定的用戶exp test/testlinshine owner=scott file=myuser.dmp4.導出特定的表空間exp test/testlinshine tablespace=users file=mytp.dmp1.導入整個數據庫imp test/testlinshine full=
3、y file=d:dumplinshine.dmp ignore=y2.導入特定的表imp test/testlinshine tables=color_admin .emp file=mytable.dmpimp test/testlinshine tables=color_admin.emp fromuser=scotttouser=new_scott file=mytable.dmp3.導入特定的用戶revoke unlimited tablespace from bl_admin;alter user bl_admin quota 0 on MES_TABLESPACE;alter u
4、ser bl_admin quota unlimited on BL_MES_DATA_TS;imp bl_admin/bladminblmes4 fromuser=mes_admin touser=bl_admin file=e:blmes.dmp log=e:imp.log1. create user backup_admin identified by backupadmin;2. GRANT EXP_FULL_DATABASE TO backup_admin;3. GRANT IMP_FULL_DATABASE TO backup_admin;4. grant create sessi
5、on,resource to backup_admin5. create directory pump_dir as E:dump;6. grant read on directory pump_dir to backup_admin導出數據庫Expdp test/testlinshine dumpfile=pump_dir:mydb.dmp schemas=color_admin job_name=rebert nologfile=y7. 導入數據庫Impdp test/testlinshine dumpfile=pump_dir:mydb.dmp remap_schema=color_ad
6、min:test job_name=rebert nologfile=yContent=metadata_only 只有表結構Data_only 只有數據ALL 所有8. 使用 expdp 和 impdp 来给方案(用户)转移表空间3.1 導出expdp system/manager DIRECTORY=dump_dir DUMPFILE=schema.dmp SCHEMAS=old_user LOGFILE=export2009021601.log3.2 導入impdp new_user/password DIRECTORY=dump_dir DUMPFILE=schema.dmp SCHE
7、MAS=old_user REMAP_SCHEMA=old_user:new_user REMAP_TABLESPACE=system:new_tablespace LOGFILE=import2009021601.logselect username,sid,serial# from v$session;alter system kill session 152,24357 immediate;drop user test cascade;grant connect ,resource to test identified by test;alter user test default ta
8、blespace test_ts temporary tablespace temp;下面介绍的是导入导出的实例。数据导出:1 将数据库 TEST 完全导出,用户名 system 密码 manager 导出到 D:daochu.dmp 中exp email=system/managerTESTsystem/managerTEST/email file=d:daochu.dmp full=y2 将数据库中 system 用户与 sys 用户的表导出exp email=system/managerTESTsystem/managerTEST/email file=d:daochu.dmp owne
9、r=(system,sys)3 将数据库中的表 inner_notify、notify_staff_relat 导出exp email=aichannel/aichannelTESTDB2aichannel/aichannelTESTDB2/email file= d:datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat) 4 将数据库中的表 table1 中的字段 filed1 以“00“打头的数据导出exp email=system/managerTESTsystem/managerTEST/email file=d:daochu
10、.dmp tables=(table1) query=“ where filed1 like “00%“上面是常用的导出,对于压缩,既用 winzip 把 dmp 文件可以很好的压缩。也可以在上面命令后面 加上 compress=y 来实现。数据的导入1 将 D:daochu.dmp 中的数据导入 TEST 数据库中。imp email=system/managerTESTsystem/managerTEST/email file=d:daochu.dmpimp email=aichannel/aichannelHUSTaichannel/aichannelHUST/email full=y
11、file=file= d:datanewsmgnt.dmp ignore=y上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。在后面加上 ignore=y 就可以了。2 将 d:daochu.dmp 中的表 table1 导入imp email=system/managerTESTsystem/managerTEST/email file=d:daochu.dmp tables=(table1)基本上上面的导入导出够用了。不少情况要先是将表彻底删除,然后导入。 Oracle 并没有提供什么参数让你将数据导入到指定的表空间中,数据默认还是导入到它原来所在的表空间。你可以用
12、IMP 的 SHOW 参数可以看到其创建脚本中会指定 TABLESPACE 参数,而这个值是原系统该对象所在的表空间,跟你用户默认的表空间是没有关系的。当然如果你建表时没特意指定表空间,那么默认的就会是用户的默认表空间。 贝壳 (22364224)2011-02-14 16:18:15 1如果目标系统中不存在跟原系统一样的表空间,这个一样,是指存储你要导入的数据的表空间如:你要导入的数据在原系统中是存放在 USERS 表空间的,而在目标系统并不存在这个表空间,那么你在导入数据时数据就会导入到目标系统中该用户的默认表空间2 如果存在一样的表空间,则在目标系统中:a) REVOKE UNLIMIT
13、ED TABLESPACE FROM 该 USERb) 取消该用户在原系统导出数据所在表空间的配额:SQLALTER USER XXX QUOTA 0 ON OLD_TABLESPACEc) 将你要存储导入数据的表空间设为该用户默认的表空间d) 添加该用户在其默认表空间中的配额:SQLALTER USER XXX QUOTA UNLIMITED ON NEW_TABLESPACE3 其他方法:a) 可以用 IMP 的 SHOW=Y 将创建脚本 SPOOL 出来,然后修改其创建脚本中的 TABLESPACE,将其修改成你所需要的表空间。b) 用第三方工具,比如 TOAD,产生其创建脚本,然后修改 TABLESPACE值,然后导入的时候加 IGNORE=Y 进行导入。c) 可以先导入数据,然后用 TOAD 的 Rebuild Multi Objects,进行数据转移。 贝壳 (22364224)2011-02-14 16:32:32 C:imp sys/sysmood as sysdba fromuser=scotttouser=scott show=y file=d:/test.dmp log=d:/scott.log这样会把建表、索引等的 DDL 语句导出到 d:/scott.log 中,不过每行都带了双引号要处理一下