Oracle數據遷移備份、授權和創建表空間、用戶


1.Oracle數據遷移備份(cmd方式)

  1. 從Oracle導出數據到本地電腦

    C:\Users\bobo>exp scott/tiger@orcl tables=emp,dept rows=y file=d:\emp_dept.dmp log=d:\emp_dept.log
    —rows是行,y代表yes
    —數據要dmp格式
    在這裏插入圖片描述

  2. 從本地電腦導入數據到Oracle

    emp_dept.dmp源數據文件導入到scott用戶

    C:\Users\bobo>imp scott/tiger@orcl fromuser=scott touser=scott file=d:\emp_dept.dmp rows=y log=d:\imp_emp_dept.log
    —fromuser是從哪個用戶導出
    —touser是導入到哪個用戶下
    在這裏插入圖片描述
    在Oracle客戶端的tables文件夾下就能看到導入的數據表
    在這裏插入圖片描述

  3. 從本地電腦導入.sql數據到Oracle

    使用@關鍵字+文件地址
    在這裏插入圖片描述

2.Oracle用戶授權

前期準備:
打開cmd窗口,輸入sqlplus scott/tiger@orcl連接Oracle數據庫
或者
在PLSQL Developer客戶端,打開sql編寫窗口,輸入以下命令也可授權。


  1. 授權/撤銷授權用戶DBA角色
    授權:grant dba to scott;
    撤銷:revoke dba from scott;

  2. 表空間授權
    創建表空間:grant create tablespace to scott;
    修改表空間:grant alter tablespace to scott;
    刪除表空間:grant drop tablespace to scott;

    授權完成後,可以在客戶端查看授權信息,也可以直接在客戶端編輯添加權限。
    在這裏插入圖片描述

  3. 用戶授權
    創建用戶:grant create user to scott;
    修改用戶:grant alter user to scott;
    刪除用戶:grant drop user to scott;
    在這裏插入圖片描述

3.創建表空間和用戶

一般是先有數據庫,然後創建N個表空間,再創建用戶,用戶可以指定該表空間,該表空間下可以存儲N張表。

  1. 創建表空間
    create tablespace test
    datafile ‘D:\oracle\product\10.2.0\oradata\orcl\test.dbf
    size 10m [autoextend on] [next 1M] [maxsize 2G];

    —datafile數據庫的路徑要真實存在
    —.dbf(database file) 數據庫文件
    —size 爲初始表空間大小,單位爲K或者M
    —autoextend 是否自動擴展,值爲on或off
    —next爲文件滿了後擴展大小
    —maxsize爲文件最大大小,值爲數值或unlimited(表示不限大小)

  2. 刪除表空間
    drop tablespace 表空間名稱;

    刪除空表空間,包括創建的數據庫文件
    drop tablespace test including contents and datafiles;

  3. 創建用戶
    create user test01 identified by test01
    default tablespace test
    temporary tablespace temp;

    —identified by:創建用戶名的口令密碼
    —默認表空間用test
    —臨時空間用temp

  4. 給test01用戶授權連接數據庫

    創建完用戶之後,在Users文件夾下能看見test01用戶,但是想登錄test01用戶顯示沒有權限去連接數據庫。
    在這裏插入圖片描述
    所以需要在system用戶下授權test01用戶連接數據庫。
    在這裏插入圖片描述
    再次按會話登錄,就能成功登錄上test01用戶。
    在這裏插入圖片描述
    test01用戶指定了test表空間,創建的表存放在test表空間下。
    在這裏插入圖片描述

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