標籤:
來自:http://blog.sina.com.cn/s/blog_62192aed01018aep.html
1 、 登入伺服器
2 、 查看磁碟空間是否夠大df -h
-h更具目前磁碟空間和使用方式 以更易讀的方式顯示
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2.9G 2.3G 521M 82% /
none 209M 0 209M 0% /dev/shm
/dev/sda2 4.5G 1.8G 2.5G 42% /u01
/dev/sde1 512M 80M 433M 16% /ocfs
-H根上面的-h參數相同,不過在根式化的時候,採用1000而不是1024進行容量轉換
[[email protected] ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.1G 2.4G 546M 82% /
none 219M 0 219M 0% /dev/shm
/dev/sda2 4.8G 1.9G 2.7G 42% /u01
/dev/sde1 537M 84M 454M 16% /ocfs
-k以單位顯示磁碟的使用方式
[[email protected] ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
su - oracle 切換到oracle使用者(linux的一個使用者名稱)
3 、 在/home/oracle/oradata 目錄下建立一個檔案夾,後面建立資料表空間需要用到
cd /home/oracle/oradata
mkdir abc
4 、 sqlplus “/ as sysdba” ( 以dba身份登入資料庫, 系統的超級使用者)
5 、建立暫存資料表空間
建立使用者前必須要先建立暫存資料表空間和資料庫資料表空間兩個資料表空間,否則用系統預設的資料表空間不好。
create temporary tablespace abc_temp tempfile‘/home/oracle/oradata/abc/abc_temp.dbf‘ size 1024m autoextend on next 100m maxsize 10240m extent management local;
說明:
1)abc_temp 暫存資料表空間名字
2)/home/oracle/oradata/abc 存放資料庫檔案的地方,一般是安裝資料庫後有控制檔案,資料檔案和記錄檔的檔案夾,再加上要建立資料表空間的名字+dbf (資料檔案)
3)1024m 資料表空間的初始大小
4)100m 資料表空間的自動成長大小
5)10240m 資料表空間最大的大小
6 、建立資料資料表空間
create tablespace abc logging datafile‘/home/oracle/oradata/abc/abc.dbf‘ size 1024m autoextend on next 100m maxsize 10240m extent management local;
7 、建立使用者並指定資料表空間
create user abc identified by abc default tablespace abc temporary tablespace abc_temp;
註:create standardtable.sql 建立表
8 、給使用者授予許可權
grant dba to abc; (給abc 使用者授予了dba 所有許可權)
9 、刪除使用者以及使用者所有的對象
drop user zfmi cascade;
cascade 參數是串聯刪除該使用者所有對象,經常遇到如使用者有對象而未加此參數則使用者刪不了的問題,所以習慣性的加此參數
刪除oracle 使用者nim 出現下面的錯誤:
SQL> drop user nim cascade;
drop user nim cascade
* ERROR 位於第 1 行:
ORA-00604: 遞迴 SQL 層 1 出現錯誤
ORA-24005: 必須使用 DBMS_AQADM.DROP_QUEUE_TABLE 刪除隊列表
處理方式:
先執行這條語句:alter session set events‘10851 trace name context forever,level 2‘;
再執行:drop user nim cascade; 刪除使用者nim
10、刪除資料表空間
前提:刪除資料表空間之前要確認該資料表空間沒有被其他使用者使用之後再做刪除
drop tablespace nimeng including contents and datafiles cascade constraints ;
including contents 刪除資料表空間中的內容,如果刪除資料表空間之前資料表空間中有內容,而未加此參數,資料表空間刪不掉,所以習慣性的加此參數
including datafiles 刪除資料表空間中的資料檔案
cascade constraints 同時刪除 tablespace 中表的外鍵參照
如果在清除資料表空間之前,先刪除了資料表空間對應的資料檔案,會造成資料庫無法正常啟動和關閉。可使用如下方法恢複:
下面的過程中, filename 是已經被刪除的資料檔案,如果有多個,則需要多次執行; tablespace_name 是相應的資料表空間的名稱。
$ sqlplus /nolog
SQL> conn / as sysdba;
如果資料庫已經啟動,則需要先執行下面這行:
SQL> shutdown abort
SQL> startup mount
SQL> alter database datafile ‘filename‘ offline drop;
SQL> alter database open;
SQL> drop tablespace tablespace_name including contents;
11 、匯出/ 匯入
匯出
1) 將資料庫 TEST 完全匯出 , 使用者名稱 system 密碼 manager 匯出到 D:daochu.dmp 中
exp system/[email protected] file=d: / daochu.dmp full=y
2) 將資料庫中 system 使用者與 sys 使用者的表匯出
exp system/[email protected] file=d: / daochu.dmp owner=(system,sys)
3) 將資料庫中的表 inner_notify 、 notify_staff_relat 匯出
exp aichannel/[email protected] file= d: / datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat)
4) 將資料庫中的表 table1 中的欄位 filed1 以 "00" 打頭的資料匯出
exp system/[email protected] file=d:daochu.dmp tables=(table1) query=" where filed1 like ‘00%‘"
上面是常用的匯出,對於壓縮,既用 winzip 把 dmp 檔案可以很好的壓縮。
也可以在上面命令後面 加上 compress=y 來實現。
匯入
1) 將 D:daochu.dmp 中的資料匯入 TEST 資料庫中。
imp system/[email protected] file=d:daochu.dmp
imp aichannel/[email protected] full=y file=d:datanewsmgnt.dmp ignore=y
上面可能有點問題,因為有的表已經存在,然後它就報錯,對該表就不進行匯入。在後面加上 ignore=y 就可以了。
2) 將 d:daochu.dmp 中的表 table1 匯入 imp system/[email protected] file=d:daochu.dmp tables=(table1)
基本上上面的匯入匯出夠用了。不少情況要先是將表徹底刪除,然後匯入。
注意:
操作者要有足夠的許可權,許可權不夠它會提示。
資料庫時可以連上的。可以用 tnsping TEST 來獲得資料庫 TEST 能否連上。
12 、 給使用者增加匯入資料許可權的操作
1) 啟動 sql*puls
2) 以 system/manager 登陸
3)create user 使用者名稱 IDENTIFIED BY 密碼
4)GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,
DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,
DBA,CONNECT,RESOURCE,CREATE SESSION TO 使用者名稱字
5) 進入 dmp 檔案所在的目錄 ,
imp userid=system/manager full=y file=*.dmp
或者 imp userid=system/manager full=y file=filename.dmp
linux下建立oracle資料表空間