oracle 常用管理命令

1、啓動oracle數據庫:

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

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

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

啓動數據庫
startup;
停止數據庫
shutdown immediate
遠程連接數據庫
sqlplus /nolog
conn sys/sys@ip:1521/orainstance as sysdba

也可以直接運行:
dbstart
#啓動數據庫的腳本
dbshut
#停止數據庫的腳本

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

shutdown

2、數據庫監聽:

啓動監聽服務:
lsnrctl start
停止監聽服務:
lsnrctl stop
查看監聽狀態:
lsnrctl status
3、用戶權限管理:

創建用戶:
create user ittbank identified by 123456 ;
賦予用戶的表空間權限:
alter user ittbank default tablespace ittbank;;
或者兩條命令合併爲:
create user ittbank identified by 123456 default tablespace ittbank;

授予用戶管理權限:
grant connect,resource,dba to ittbank ;
刪除用戶
drop user“name”cascade;
注:cascade參數是級聯刪除該用戶所有對象,經常遇到如用戶有對象而未加此參數則用戶刪不了的問題,所以習慣性的加此參數。“name”的引號有無都是一樣的。

查看當前用戶的角色
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
]
[exception
]
end

set serveroutput on //打開輸出開關
begin
dbms_output.put_line('hello world!'); //輸出結果
end;
修改連接數:(注:要重啓數據庫)
alter system set processes=1000 scope=spfile;
shutdown immediate;
startup;

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