oracle 11g 最常用的基本管理命令,包括建立使用者、表空間、許可權等
Oracle 11g最常用的基本管理命令,包括建立使用者、表空間,許可權分配等
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
#啟動資料庫的指令碼
#停止資料庫的指令碼
參考:
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、
授予使用者管理許可權: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;