Oracle資料庫常用操作sql語句

來源:互聯網
上載者:User

標籤:identified   management   including   default   contents   

1.--建立資料表空間
create tablespace cmdb_db datafile ‘\home\cmdb_11.dbf‘ size 100m autoextend on next 50m extent management local;
2.--建使用者
create user cmdb_1023 identified by admin default tablespace cmdb_db;
3.--給許可權
grant connect,resource,dba to cmdb_db;
4.--匯入資料(在命令視窗執行)
imp cmdb/admin file=/home/cmdb_henan.dmp fromuser=cmdb_L touser=cmdb;
5.--匯出資料
exp cmdn/admin owner=cmdb file=/u01/app/oracle/cmdb_heinan.dmp;
6.--刪除資料表空間
drop tablespace CMDB_db including contents and datafiles;
7.--查看錶空間與檔案路徑
select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files order by file_id;
8.--刪除使用者並刪除使用者下所有資料
drop user cmdb_perftests cascade;

    • 刪除過程中可能遇到報錯:cannot drop a user that is currently connected 提示有人串連使用者,不能夠刪除!此時請使用以下語句,刪除串連再刪使用者。

    • select sid,serial# from v$session where username=‘CMDB_HLJ‘;   查詢CMDB_HLJ這個資料庫正在串連的SID,SERIAL#

    • alter system kill session ‘54,5‘;   殺死串連‘SID,SERIAL‘

    • alter system kill session ‘98,select * from sys.dba_tablespaces;23‘; 殺死串連‘SID,SERIAL‘

    • alter system kill session ‘137,3‘; 殺死串連‘SID,SERIAL‘

    • DROP USER CMDB_HLJ cascade; 刪除使用者

9.--查看錶空間名稱
select * from sys.dba_tablespaces;
10.--匯出資料庫,空表未匯出問題(第一次匯出時執行)
select ‘alter table ‘||table_name||‘ allocate extent;‘ from user_tables where num_rows=0;複製此語句的執行結果,刪除所有不是alter table 開頭的語句,再次執行複製的語句。《註:串連使用者為當前要執行的使用者》

Orcale資料庫與監聽啟動與停止操作
   (1) 以oracle身份登入資料庫,命令:su – oracle   (2) 進入Sqlplus控制台,命令:sqlplus /nolog   (3) 以系統管理員登入,命令:connect / as sysdba   (4) 啟動資料庫,命令:startup   (5) 如果是關閉資料庫,命令:shutdown immediate   (6) 退出sqlplus控制台,命令:exit   (7) 進入監聽器控制台,命令:lsnrctl   (8) 啟動監聽器,命令:start   (9) 退出監聽器控制台,命令:exit   (10) 重啟資料庫結束


Oracle資料庫常用操作sql語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.