(總結)Oracle 11g常用管理命令(使用者、資料表空間、許可權)

來源:互聯網
上載者:User

標籤:

1、啟動oracle資料庫:

從root切換到oracle使用者進入:
su - oracle

進入sqlplus環境,nolog參數表示不登入:
sqlplus /nolog

以管理員模式登入:
sqlplus / as sysdba

啟動資料庫
startup;
停止資料庫
shutdown immediate
遠端連線資料庫
sqlplus /nolog
conn sys/[email protected]:1521/orainstance as sysdba
也可以直接運行:
dbstart
#啟動資料庫的指令碼
dbshut
#停止資料庫的指令碼

參考:
startup [force][restrict][nomount][migrate][quiet]
[pfile=]
[mount [exclusive] x |
open
]

shutdown

註:要把Linux下的Oracle配置成服務自啟動,請看:
(原創)CentOS Linux下配置Oracle 11gR2為系統服務自動啟動

2、資料庫監聽:

啟動監聽服務:
lsnrctl?start
停止監聽服務:
lsnrctl stop
查看監聽狀態:
lsnrctl status
3、使用者權限管理:

註:以下命令都需要DBA許可權。
建立使用者:
create user ittbank identified by 123456 ;
賦予使用者的資料表空間許可權:
alter user ittbank default tablespace ittbank;;
或者兩條命令合并為:
create user ittbank identified by 123456 default tablespace ittbank;

註:剛剛建立完的新使用者是沒有任何許可權的,甚至連登入資料庫的許可權都沒有。這時使用conn 使用者名稱/密碼 會提示沒有許可權。在建立一個使用者之後還要對這個使用者進行授權操作。當然是要使用有能力授權的使用者,如sys、system。角色是指由系統許可權集合。通常給某個使用者授予許可權時如果沒有角色存在的話,那麼需要一條一條的操作,角色的存在就是使得授權變得很方便。通常一個角色由多個系統許可權組成。常用的角色有三個connect(7種許可權)、dba、resource(在任何錶空間建表)。

授予使用者系統管理權限:
grant connect,resource,dba to ittbank ;

刪除使用者
drop user"name"cascade;
註:cascade參數是串聯刪除該使用者所有對象,經常遇到如使用者有對象而未加此參數則使用者刪不了的問題,所以習慣性的加此參數。"name"的引號有無都是一樣的。

修改使用者密碼
password ittbank( 在使用者已經串連的情況下 )或者
alter user ittbank identified by newpassword
注意:在給其他使用者修改密碼時,需要具有DBA的許可權或擁有alter user的系統許可權。

查看目前使用者的角色
select * from user_role_privs;
select * from session_privs;
查看目前使用者的系統許可權和表級許可權
select * from user_sys_privs;
select * from user_tab_privs;
查詢使用者表
select name from dba_users;
修改使用者口令
alter user "name" identified by "password";
顯示目前使用者
show user;

4、資料表及資料表空間:

建立資料表空間:
create tablespace ittbank datafile ‘/u01/app/oracle/oradata/ORCL/ittbank.dbf‘ size 300m autoextend on;
說明:末尾帶autoextend on參數表示當資料表空間大小不夠用時會自動擴容,所有建議加上autoextend on參數。

刪除資料表空間:
drop tablespace ittbank including contents and datafiles;
修改資料表空間大小(註:修改=可以增大,可以減小。)
alter?database?datafile ‘/u01/app/oracle/oradata/ORCL/ittbank.dbf‘ resize 200m;
增加資料表空間大小(註:增加=只能增大,不能減少。)
alter tablespace ittbank add datafile ‘/u01/app/oracle/oradata/ORCL/ittbank.dbf‘ size 2048m;
查詢資料庫檔案:
select * from dba_data_files;
查詢當前存在的資料表空間:
select * from v$tablespace;
資料表空間情況:
select tablespace_name,sum(bytes)/1024/1024 from dba_data_files?group?by tablespace_name;
查詢資料表空間剩餘空間:
select tablespace_name,sum(bytes)/1024/1024 from dba_free_space group by tablespace_name;
查看錶結構:
desc table;
查看使用者當前串連數:
select count(*) from sys.v_$session;
pl/sql
[declare
/*申明部分,一般是變數及常量*/]
[ begin
/*執行部分,流程結構控制,sql部分*/]
[exception
/*異常處理部分*/]
end

set serveroutput on //開啟輸出開關
begin
dbms_output.put_line(‘hello world!‘); //輸出結果
end;
修改串連數:(註:要重啟資料庫)
alter system set processes=1000?scope=spfile;
shutdown immediate;
startup;

(總結)Oracle 11g常用管理命令(使用者、資料表空間、許可權)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.