oracle常用管理命令

2021-09-08 17:53:53 字數 4542 閱讀 8627

啟動資料庫和監聽

lsnrctl start

sqlplus

/nolog

conn sys/as

sysdba

startup

檢視當前的例項名

show parameter instance_name;

檢視當前登陸的使用者

show user;

修改密碼

修改使用者的密碼

password username

或者:

conn system/manager

alter user scott identified by 123456;

設定顯示行的寬度

show linesize;  --預設是80

set linesize 100

設定每頁顯示的行數

show pagesize;   --預設是14

set pageszie 10

設定字段顯示的長度

col ename for a10;

建立臨時表空間

建立表空間

刪除表空間

drop tablespace tablespace_name including contents and datafiles;

改變表空間的狀態

alter tablespace zytp offline;   --

離線alter tablespace zytp online; --聯機

alter tablespace zytp read only; --唯讀

拓展表空間

resize 100m; --增加資料檔案的大小

移動資料檔案(有時乙個磁碟的i/o過於繁忙或者損壞,我們需要移動資料檔案)

--

移動回系統表空間的資料檔案

select tablespace_name from dba_data_files where

file_name='

j:\disk1\test.dbf

'; --

查詢出表空間的名字

alter tablespace test offline; --

使表空間離線

host move j:\disk1\test.dbf j:\disk2\test.dbf --

在物理上完成移動

alter tablespace test rename datafile '

j:\disk1\test.dbf'to

'j:\disk2\test.dbf

'; --

從邏輯上移動

alter tablespace test online; --

使表空間聯機

--移動系統表空間,重做日誌檔案也是相同的步驟

shutdown immediate --

關閉資料庫

startup mount     --

將資料庫置為載入狀態

alter

database rename file''

to'j:\disk1\system01.dbf

';

alter

database

open;

建立單列索引

create index myemp_idx1 on myemp(ename);     --按照ename查詢將大大加快

建立復合索引

create index myemp_idx2 on myemp(ename,job);   --與(job,ename)是兩個不相同的索引

建立使用者

create user

test1

identified by test1 default tablespace listp temporary tablespace tblspace_temp;

刪除使用者

drop user user_name cascade;     --如果該使用者已經建立了表,就要使用cascade引數

給使用者授權

資料庫許可權分為:

物件許可權:使用者對其它使用者的資料物件操作的許可權;資料物件是指:比如檢視,表,過程

grant connect to test1;    --connect其實是預定義角色(還有一種叫自定義角色),包含7種許可權,允許使用者連線資料庫

grant resource to test1; --允許使用者建立表,序列等

garnt select on scott.emp to test1; --允許test1使用者查詢scott.emp表,授權的使用者位dba或者scott

grant all on scott.emp to test1; --把emp表的insert,update,drop,select許可權給test1使用者

grant select any table to test1; --授權查詢所有使用者的表

grant all on scott.emp to test1 with grant option; --給test1使用者授權的同時也給test1使用者給其它使用者授權這張表的許可權,如果test1的許可權**,其它使用者也將被**

**許可權

revoke

allon scott.emp from test11; --誰受的許可權,就得由誰收回,dba使用者也能代替

角色

角色分為自定義角色預定義角色,預定義角色最常見的三個角色是connect,resource和dba,一般的使用者具有前兩個角色就可以了

檢視角色有哪些許可權

select

*from dba_sys_privs where grantee=

'resource

'; --

檢視角色所擁有的許可權或者乙個使用者所具有的許可權

select

*from dba_role_privs where grantee=

'scott'--

檢視乙個使用者所具有的角色

select

*from dba_roles; --

檢視所有角

建立自定義角色

create role myrole not identified;                         --

不需要驗證的角色,也可以不寫,預設的是不要密碼的

grant create session,create view to myrole with admin option; --給角色授權,系統許可權,並且可以傳遞

grant select on scott.emp to myrole;                     --授予角色物件的許可權

grant select any table,myrole to scott;                   --同時將系統許可權和角色賦予scott使用者

使用profile管理使用者口令

create profile lock_account limit failed_login_attempts 3 password_lock_time 2;   --嘗試3次,鎖定2天

alter user test1 profile lock_account; --test1使用lock_account

create profile limit_account limit password_life_time 10 password_grace_time 2 password_reuse_time 10; --10天修改密碼,寬限兩天,10天之內不可重用密碼 (預設180天,寬限7天)

alter user test1 account unlock; --解鎖使用者

drop profile lock_account cascade; --刪除profile檔案,刪除後所有的限制將被取消

Oracle管理常用命令

第八章 managing password security and resources 1.controlling account lock and password sql alter user juncky identified by oracle account unlock 2.user ...

ORACLE 常用管理指令碼

1 表空間統計 a 指令碼說明 這是我最常用的乙個指令碼,用它可以顯示出資料庫中所有表空間的狀態,如表空間的大小 已使用空間 使用的百分比 空閒空間數及現在表空間的最大塊是多大。b 指令碼原文 select upper f.tablespace name 表空間名 d.tot grootte mb ...

oracle常用管理sql

oracle監控函式 檢視所有表空間利用率 select a.a1 表空間名稱,c.c2 型別,c.c3 區管理,b.b2 1024 1024 表空間大小m,b.b2 a.a2 1024 1024 已使用m,substr b.b2 a.a2 b.b2 100,1,5 利用率 from select ...