使用imp導入備份數據到oracle 12 c 的操作

-- 1.首先完成cdb中的全部操作:
-- 查看指定用戶是否存在,若存在,將其刪除;
-- 其次查看指定的默認和臨時表空間是否存在,若存在,將其刪除;
-- 最後創建默認和臨時表空間。

-- 1.1 查看指定用戶是否存在,如果存在,則刪除該用戶
select username 
from dba_users
where username like '_#%';

--刪除指定用戶,此時的用戶有很多表,需要級聯刪除(使用cascade)關鍵字
drop user C##FACTORY cascade;

-- 1.2 查看指定的默認表空間是否存在,如存在,則刪除該表空間
select d.tablespace_name
from dba_tablespaces t , dba_data_files d
where t.tablespace_name=d.tablespace_name and t.tablespace_name like 'FACTORY%';

--刪除默認表空間和數據文件
alter tablespace factory_data offline;
drop tablespace factory_data including contents and datafiles; -- 刪除默認表空間,因爲此時表空間是有數據的,需要including contents

-- 1.3 查看指定的臨時表空間是否存在,如存在,則刪除該表空間
select t.tablespace_name
from dba_temp_free_space t 
where t.tablespace_name like 'FACTORY%';

--刪除臨時表空間和數據文件
drop tablespace factory_temp including contents and datafiles; -- 刪除默認表空間,因爲此時表空間是有數據的,需要including contents

-- 1.4 創建默認表空間 
create tablespace factory_data
logging
datafile 'F:\Oracle\tablespaces\FACTORY_DATA\cdb_factory_data.dbf' size 2048m
autoextend on next 20m
extent management local;

--創建臨時表空間
create temporary tablespace factory_temp
tempfile 'F:\Oracle\tablespaces\FACTORY_DATA\cdb_factory_temp.dbf' size 2048m
autoextend on next 20m
extent management local;

-- 2.其次完成pdb中的全部操作

-- 2.1 將數據庫切換爲pdb,然後創建與cdb同樣的用戶、
alter session set container = orclpdb;

-- 2.2 打開數據庫
alter database orclpdb open;

-- 2.3 查看指定默認表空間是否存在,如存在,將其刪除
select t.tablespace_name
from dba_tablespaces t,dba_data_files d
where t.tablespace_name=d.tablespace_name and  t.tablespace_name like 'FACTORY%';

-- 刪除默認表空間和數據文件
alter tablespace factory_data offline;
drop tablespace FACTORY_DATA including contents and datafiles;

-- 2.4 查看指定的臨時表空間是否存在,如存在,將其刪除
select t.tablespace_name
from dba_tablespaces t,dba_temp_free_space d
where t.tablespace_name=d.tablespace_name and t.tablespace_name like 'FACTORY%';

-- 刪除臨時表空間和數據文件
drop tablespace FACTORY_TEMP including contents and datafiles;

-- 2.5 創建默認表空間 
create tablespace factory_data
logging
datafile 'F:\Oracle\tablespaces\FACTORY_DATA\pdb_factory_data.dbf' size 2048m
autoextend on next 20m
extent management local;

-- 2.6 創建臨時表空間
create temporary tablespace factory_temp
tempfile 'F:\Oracle\tablespaces\FACTORY_DATA\pdb_factory_temp.dbf' size 2048m
autoextend on next 20m
extent management local;

-- 2.7 查看容器名稱
show con_name;

-- 3.最後將數據庫切換會cdb後創建用戶,指定用戶表空間,指定用戶權限‘
alter session set container =cdb$root;

-- 3.1 開始創建用戶
create user c##factory identified by factory;
alter user c##factory default tablespace factory_data; --指定默認表空間
alter user c##factory temporary tablespace factory_temp; --指定臨時表空間
grant connect,dba to c##factory; --授予用戶權限

conn c##factory/factory

--4.使用imp導入備份數據到數據庫中:

imp 用戶名/密碼@主機ip地址/數據庫實例名  file=數據庫備份文件的完整路徑(如:d:\databack\backup.dmp) full=y ignore=y

耐心等待數據導完。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章