Oracle 使用SqlPlus管理

來源:互聯網
上載者:User

標籤:

Oracle 使用SqlPlus

安裝,一鍵安裝,很簡單。安裝過程,一定要記住密碼

串連本機伺服器,可以直接,開啟cmd:

可以直接不用登陸,如果登陸需要輸入使用者名稱、密碼。

sqlplus /nolog

也可以,注意斜杠後有空格

sqlplus / as  sysdba

 

串連

conn /as sysdba

sqlplus使用需要協助時,可以使用:

help index

可以看到如下:

 

查看使用者

show user;

修改密碼:

alter user system identified by system;

使用者串連 

connect system/system;

 

 

查詢所有的schema

select username from dba_users;

查詢使用者下所有的表:

select table_name from dba_tables where owner=‘system‘;

 

三、備份與還原

備份資料庫:

exp demo/demo@orcl buffer=1024 file=d:\back.dmp full=y

 

demo:使用者名稱、密碼 

buffer: 緩衝大小

file: 具體的備份檔案地址 

full: 是否匯出全部檔案 

ignore: 忽略錯誤,如果表已經存在,則也是覆蓋

 

將資料庫中system使用者與sys使用者的表匯出 

exp demo/[email protected] file=d:\backup\1.dmp owner=(system,sys)

 匯出指定的表 

exp demo/[email protected] file=d:\backup2.dmp tables=(teachers,students)

 按過濾條件,匯出 

exp demo/[email protected] file=d:\back.dmp tables=(table1) query=\" where filed1 like ‘fg%‘\"

 匯出時可以進行壓縮: 

命令後面 加上 compress=y 

 

 

還原資料庫:

開啟cmd直接執行如下命令,不用再登陸sqlplus。

imp demo/demo@orcl file=d:\back.dmp full=y ignore=y

匯入指定表:

imp demo/demo@orcl file=d:\backup2.dmp tables=(teachers,students)

 

四、解決11G後,空表無法匯出的問題

11G中有個新特性,當表無資料時,不分配segment,以節省空間的。這樣在匯出資料的時候,空表不被匯出

解決方案:

1、insert一行,再rollback就產生segment了。

  該方法是在在空表中插入資料,再刪除,則產生segment。匯出時則可匯出空表。

2、設定deferred_segment_creation 參數

該參數值預設是TRUE,當改為FALSE時,無論是空表還是非空表,都分配segment。

需注意的是:該值設定後對以前置入的空表不產生作用,仍不能匯出,只能對後面新增的表產生作用。如需匯出之前的空表,只能用第一種方法。

需要查詢所有的空表,然後執行

select ‘alter table ‘||table_name||‘ allocate extent;‘ from user_tables where num_rows=0

然後再匯出即可。

 

Oracle 使用SqlPlus管理

聯繫我們

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