第一部分:導出 ==================================== --創建緩存目錄,必須使用DBA權限用戶創建,dump_dir為緩存目錄名稱可自定義命名,AS后的系統目錄需要真實存在 CREATE OR REPLACE DIRECTORY dump_dir AS 'D:/temp'; --可以查詢DBA已經建立了哪些緩存目錄 SELECT * FROM dba_directories; --為全部用戶授權,未授權的用戶無權使用該緩存目錄進行導入、導出操作 GRANT read,write ON DIRECTORY dump_dir TO public; --執行導出操作--DOS下 expdp 賬號/密碼@本地服務名 DIRECTORY=dump_dir DUMPFILE=xxx.dmp LOGFILE=xxx.log SCHEMAS=賬號 --示例 expdp scott/tiger@orcl DIRECTORY=dump_dir DUMPFILE=scott.dmp LOGFILE=scott.log SCHEMAS=scott ---------------------------------------------------------------- 第二部分:導入 ==================================== --創建緩存目錄、為用導入用戶授權等同第一部分,此處省略 --導入示例 --導入文件scott.dmp要放在dump_dir對應的實際目錄下,即第一部分中的D:/temp下 --說明:SCHEMAS為導出文件所屬用戶名,如導入到其他名稱的用戶下應使用REMAP_SCHEMA重新映射一下,示例中從scott用戶導出再導入到tom的用戶下 --具備DBA權限的用戶可以不指定SCHEMAS,系統會自動從導入文件中提取,但是導入到其他用戶下必須得REMAP_SCHEMA一下 impdp scott/tiger@orcl DIRECTORY=dump_dir DUMPFILE=scott.dmp SCHEMAS=scott REMAP_SCHEMA=scott:tom --修改表空間和用戶名的示例 impdp tom/jerry@orcl DIRECTORY=dump_dir DUMPFILE=scott.dmp LOGFILE=tom.log SCHEMAS=scott REMAP_SCHEMA=scott:tom REMAP_TABLESPACE=users:tbs_tom,temp:tbs_tom_temp ---------------------------------------------------------------- 第三部分:創建表空間、授權等 ==================================== --創建表空間,名稱和文件路徑根據實際指定 create tablespace 表空間名稱 datafile 'D:/apps/oracle/oradata/orcl/表空間名稱.dbf' size 100M autoextend on next 100M maxsize unlimited; --示例 create tablespace tbs_tom datafile 'D:/apps/oracle/oradata/orcl/tom01.dbf' size 100M autoextend on next 100M maxsize unlimited; --創建臨時表空間 create temporary tablespace 臨時表空間名稱 tempfile 'D:/apps/oracle/oradata/orcl/臨時表空間名稱.dbf' size 100M autoextend on next 100M maxsize unlimited; --示例 create temporary tablespace tbs_tom_temp tempfile 'D:/apps/oracle/oradata/orcl/tom_temp01.dbf' size 100M autoextend on next 100M maxsize unlimited; --創建用戶並授權 create user 用戶名 identified by 密碼 default tablespace 表空間名稱 temporary tablespace 臨時表空間名稱; --示例 create user tom identified by jerry default tablespace tbs_tom temporary tablespace tbs_tom_temp; --授權 grant connect,resource,create view,create session,dba to 用戶名; --示例 grant connect,resource,create view,create session,dba to tom; --不限制用戶對表空間的使用 alter user 用戶名 quota unlimited on 表空間名稱; --示例 alter user tom quota unlimited on tbs_tom; ---------------------------------------------------------------- 第四部分:刪除表空間、用戶等 ==================================== --刪除用戶 drop user 用戶名 cascade; --示例 drop user tom cascade; --刪除表空間 DROP TABLESPACE 表空間名稱 INCLUDING CONTENTS AND DATAFILES; --示例 DROP TABLESPACE tbs_tom INCLUDING CONTENTS AND DATAFILES; DROP TABLESPACE tbs_tom_temp INCLUDING CONTENTS AND DATAFILES;
