備份資料庫
創建備份目錄(用sys賬號),若已創建備份目錄,此步可忽略
create directory db_bak as 'D:\ ECIMS_DB'
--查看創建的目錄 select * from dba_directories --洗掉已創建的目錄 drop directory DB_BAK 格式: drop directory 目錄名
備份(匯出)資料庫(cmd狀態下)
expdp XXX/XXX@XXX schemas=XXX dumpfile=XXX_20181130.dump logfile=XXX_20181130.LOG DIRECTORY=DB_BAK 語法: expdp 用戶名/密碼@實體名 schemas=用戶名 dumpfile=匯出dump檔案名.dump logfile=匯出日志檔案名.LOG DIRECTORY=DB_BAK
匯入資料庫
步驟一、匯入前,先洗掉賬號(plsql狀態下)
drop user XXX cascade; 格式: drop user 用戶名 cascade;
注:若洗掉不掉,需先洗掉所有會話!!!
select username, sid, serial# from v$session where username='XXX' --找到用戶SESSION 格式: select username, sid, serial# from v$session where username='用戶名' --找到用戶SESSION 注:若有多潭訓話,需批量洗掉 alter system kill session '249,57377' --殺掉用戶SESSION 'sid,serial#' alter system kill session '250,57376' --殺掉用戶SESSION 'sid,serial#' alter system kill session '251,57375' --殺掉用戶SESSION 'sid,serial#' 格式: alter system kill session 'sid,serial'
步驟二、創建賬號,賦予權限(plsql狀態下)
create user XXX identified by XXX default tablespace USERS temporary tablespace TEMP profile DEFAULT; -- Grant/Revoke role privileges grant connect to XXX; grant dba to XXX; grant resource to XXX; -- Grant/Revoke system privileges grant alter any sequence to XXX; grant alter any table to XXX; grant alter any trigger to XXX; grant change notification to XXX; grant create any procedure to XXX; grant create any sequence to XXX; grant create any table to XXX; grant create any type to XXX; grant create any view to XXX; grant unlimited tablespace to XXX; -------------------------------------------------------------- 格式: create user 用戶名 identified by 密碼 default tablespace USERS temporary tablespace TEMP profile DEFAULT; -- Grant/Revoke role privileges grant connect to 用戶名; grant dba to 用戶名; grant resource to 用戶名; -- Grant/Revoke system privileges grant alter any sequence to 用戶名; grant alter any table to 用戶名; grant alter any trigger to 用戶名; grant change notification to 用戶名; grant create any procedure to 用戶名; grant create any sequence to 用戶名; grant create any table to 用戶名; grant create any type to 用戶名; grant create any view to 用戶名; grant unlimited tablespace to 用戶名;
步驟三、匯入資料(cmd狀態下)
impdp XXX/XXX DIRECTORY=db_bak DUMPFILE=XXX.dump logfile=XXX.log REMAP_SCHEMA=XXX:XXX remap_tablespace=XXX:XXX 格式 impdp 用戶名/密碼 DIRECTORY=db_bak DUMPFILE=備份檔案名.dump logfile=備份日志檔案名.log REMAP_SCHEMA=匯出用戶名:匯入用戶名 remap_tablespace=匯出表空間:匯入表空間
方式二備份及匯入(推薦)
--備份資料庫 expdp YZJ_TEST/YZJ_TEST@ECIMS schemas=YZJ_TEST dumpfile=YZJ_TEST_20181130.dump logfile=YZJ_TEST_20181130.LOG DIRECTORY=DB_BAK --洗掉帳號 drop user YZJ_TEST cascade; --查看賬號連接數量 select username, sid, serial# from v$session where username='YZJ_TEST' --找到用戶SESSION alter system kill session '249,57377' --殺掉用戶SESSION 'sid,serial#' /*第1步:創建臨時表空間 */ create temporary tablespace DMIS_STD_TEMP tempfile 'F:\app\Administrator\oradata\ECIMS\DMIS_STD_TEMP.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local; /*第2步:創建資料表空間 */ create tablespace DMIS_STD_DATA logging datafile 'F:\app\Administrator\oradata\ECIMS\DMIS_STD_DATA.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local; /*第3步:創建用戶并指定表空間 */ create user DMIS_STD identified by DMIS_STD default tablespace DMIS_STD_DATA temporary tablespace DMIS_STD_TEMP; 3、匯入陳述句按下面的方式 impdp system/eMarine123 DIRECTORY=db_bak DUMPFILE=ERIM_PROD.dump logfile=ERIM_PROD_imp.log REMAP_SCHEMA=ERIM_PROD:<新用戶名> remap_tablespace=ERIM_PROD:<新表空間名>
注意事項!!
注:若是新資料庫,需要執行第2、3步驟,舊資料庫無需執行!!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/34218.html
標籤:Oracle
上一篇:資料庫報ORA-12514
