用Oracle10g自帶的企業(yè)管理器或PL/SQL圖形化的方法創(chuàng)建表空間和用戶以及分配權(quán)限是相對比較簡單的,本文要介紹的是另一種方法,使用Oracle 9i所帶的命令行工具:SQLPLUS
來創(chuàng)建表空間,這個方法用起來更加簡明快捷。
假設(shè): 文章假設(shè),如果您用的是Linux系統(tǒng),那么Oracle用戶名為oracle。同時,您是在oracle服務(wù)器上操作。
如果是在Windows系統(tǒng)下, 請先點擊“開始”,然后點“運(yùn)行”,輸入cmd并點擊“確定”,打開命令行窗口
如果是在Linux的圖形窗口,請右鍵點擊桌面并點擊“打開終端”,然后輸入 su - oracl
做好上述準(zhǔn)備工作以后,輸入以下命令:
1
2
3
4
|
sqlplus /nolog 回車后,將出現(xiàn)提示符 SQL> 這時輸入 conn / as sysdba |
一般即可登錄,如果失敗的話,可以試一下用conn sys/sys用戶的密碼 as sysdba來重試一下
接下來,我們看看您當(dāng)前的數(shù)據(jù)庫文件一般都是放在哪里的:
1
2
3
4
5
6
7
8
9
10
11
|
select name from v$datafile; windows下可能看到的結(jié)果如下: SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- D:\oracle\oradata\orcl\system01.dbf D:\oracle\oradata\orcl\undotbs01.dbf D:\oracle\oradata\orcl\cwmlite01.dbf D:\oracle\oradata\orcl\drsys01.dbf D:\oracle\oradata\orcl\indx01.dbf D:\oracle\oradata\orcl\tools01.dbf |
說明您的數(shù)據(jù)文件是放在 D:\oracle\/oradata\orcl\ 這個目錄下的
Linux下可能看到的結(jié)果如下:
1
2
3
4
5
6
7
8
9
|
SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /oracle/oradata/orcl/system01.dbf /oracle/oradata/orcl/undotbs01.dbf /oracle/oradata/orcl/cwmlite01.dbf /oracle/oradata/orcl/drsys01.dbf /oracle/oradata/orcl/indx01.dbf /oracle/oradata/orcl/tools01.dbf |
說明您的數(shù)據(jù)文件是放在 /oracle/oradata/orcl/ 這個目錄下的
好,我們可以開始創(chuàng)建數(shù)據(jù)庫表空間了,創(chuàng)建數(shù)據(jù)庫表空間的命令格式如下:
1
|
create tablespace 表空間名 datafile '對應(yīng)的文件名' size 大小; |
舉例如下:
對于上述的windows情況:
1
|
create tablespace yang datafile 'D:\oracle\oradata\orcl\yang.dbf' size 3000m; |
3000m指的是3000MB
對于上述的Linux的情況:
1
|
create tablespace yang datafile '/oracle/oradata/orcl/yang.dbf' size 3000m; |
至此,所需的表空間已建立。
接下來我們開始創(chuàng)建用戶,創(chuàng)建用戶的命令格式如下:
1
|
create user 用戶名 identified by 密碼 default tablespace 用戶默認(rèn)使用哪一個表空間; |
修改用戶的權(quán)限:
1
|
grant 角色1,角色2 to 用戶名; |
舉例如下:
1
2
|
create user yanglei identified by yang123 default tablespace yang; grant dba, connect to yanglei; |
授權(quán)成功。
ps:下面看下Oracle創(chuàng)建用戶的方法,具體代碼如下所示:
創(chuàng)建用戶
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
-- Create the user create user MEP identified by whq1987 default tablespace MEP temporary tablespace MEP_TEMP profile DEFAULT ; -- Grant/Revoke role privileges grant connect to MEP; grant datapump_exp_full_database to MEP; grant datapump_imp_full_database to MEP; grant dba to MEP; grant exp_full_database to MEP; grant imp_full_database to MEP; grant resource to MEP; -- Grant/Revoke system privileges grant alter_user to MEP; grant comment any table to MEP; grant create any view to MEP; grant create session to MEP; grant create user to MEP; grant delete any table to MEP; grant drop user to MEP; grant export full database to MEP; grant unlimited tablespace to MEP; |
總結(jié)
以上所述是小編給大家介紹的使用sqlplus為oracle創(chuàng)建用戶和表空間的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對服務(wù)器之家網(wǎng)站的支持!
原文鏈接:https://www.cnblogs.com/furenjian/articles/2889787.html