標籤:
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管理