oracle管理、備份與恢復(fù)
創(chuàng)新互聯(lián)建站是一家專業(yè)提供加查企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為加查眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
管理數(shù)據(jù)庫(kù)的用戶是sys、system,可以將sys比作董事長(zhǎng),system比作總經(jīng)理,兩者有如下區(qū)別
1、最重要的區(qū)別,存儲(chǔ)的數(shù)據(jù)的重要性不一樣
sys:所有oracle的數(shù)據(jù)字典的基表和視圖都存放在sys用戶中,這些基表和視圖對(duì)于oracle的運(yùn)行
是至關(guān)重要的,由數(shù)據(jù)庫(kù)自己維護(hù),任何用戶都不能手動(dòng)更改。sys用戶擁有dba、sysdba、sysoper
角色或權(quán)限,是oracle權(quán)限最高的用戶
system:用于存放次一級(jí)的內(nèi)部數(shù)據(jù),如oracle的一些特性或工具的管理信息。system用戶擁有
dba、sysdba角色或系統(tǒng)權(quán)限
2、其次的區(qū)別,權(quán)限的不同
sys用戶必須以as sysdba或as sysoper形式登錄,不能以正常的方式登錄數(shù)據(jù)庫(kù)
system如果正常登錄,它其實(shí)就是一個(gè)普通dba用戶,但是如果as sysdba登錄,其結(jié)果實(shí)際上是作為sys用戶登錄的
從登錄信息里面可以看出來(lái)
sysdba和sysoper的相同與不同,none為沒(méi)有,也就是不同
startup數(shù)據(jù)庫(kù) startup
shutdown數(shù)據(jù)庫(kù) shutdown
alter database open/mount /backup alter database open/mount /backup
改變字符集 none
create database(創(chuàng)建數(shù)據(jù)庫(kù)) none
drop database(刪除數(shù)據(jù)庫(kù)) none
create spfile create spfile
alter database archivelog(歸檔日志) alter database archivelog(歸檔日志)
alter database recovery恢復(fù)數(shù)據(jù)庫(kù) 只能完全恢復(fù),不能執(zhí)行不完全恢復(fù)
擁有restricted session會(huì)話限制 擁有restricted session會(huì)話限制
可以讓用戶作為sys用戶連接 可以進(jìn)行一些基本的操作,但不能查看用戶數(shù)據(jù)
登錄之后用戶是sys 登錄之后用戶是public
dba權(quán)限的用戶
dba用戶是指具有dba角色的數(shù)據(jù)庫(kù)用戶,特權(quán)用戶可以執(zhí)行啟動(dòng)實(shí)例,關(guān)閉實(shí)例等特殊操作
而dba用戶只能在啟動(dòng)數(shù)據(jù)庫(kù)后才能執(zhí)行各種管理操作
管理初始化參數(shù)
顯示初始化參數(shù)
1、show parameter 顯示系統(tǒng)參數(shù)
SQL> show parameter;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
O7_DICTIONARY_ACCESSIBILITY boolean FALSE
active_instance_count integer
aq_tm_processes integer 0
archive_lag_target integer 0
asm_diskgroups string
asm_diskstring string
asm_power_limit integer 1
Oracle數(shù)據(jù)庫(kù)的備份與恢復(fù)
邏輯備份是指使用工具export將數(shù)據(jù)對(duì)象的結(jié)構(gòu)和數(shù)據(jù)導(dǎo)出文件的過(guò)程(數(shù)據(jù)導(dǎo)出到磁盤),邏輯恢復(fù)
是指當(dāng)數(shù)據(jù)庫(kù)對(duì)象被誤操作而損壞后使用工具import利用備份的文件把數(shù)據(jù)對(duì)象導(dǎo)入到數(shù)據(jù)庫(kù)的過(guò)程
物理備份即可在數(shù)據(jù)庫(kù)open的狀態(tài)下進(jìn)行也可在關(guān)閉數(shù)據(jù)庫(kù)后進(jìn)行,但是邏輯備份和恢復(fù)只能在open的狀態(tài)下進(jìn)行
導(dǎo)出:
導(dǎo)出具體分為:導(dǎo)出用戶某張表,導(dǎo)出各用戶schema,導(dǎo)出整個(gè)數(shù)據(jù)庫(kù)三種方式
導(dǎo)出使用exp命令來(lái)完成,下面是常見(jiàn)的選項(xiàng)
userid:用于指定執(zhí)行導(dǎo)出操作的用戶名,口令,連接字符串
tables:用于指定導(dǎo)出操作的表
owner:用于指定執(zhí)行導(dǎo)出操作的方案
full=y:用于指定執(zhí)行導(dǎo)出操作的數(shù)據(jù)庫(kù)
inctype:用于指定執(zhí)行導(dǎo)出操作的增量類型
rows:用于指定執(zhí)行導(dǎo)出操作是否要導(dǎo)出表中的數(shù)據(jù)
file:用于指定導(dǎo)出文件名
導(dǎo)出表:
1、導(dǎo)出自己的表(表的數(shù)據(jù))
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@test tables=emp file=/oracle/test/scott_emp.dmp
Export: Release 11.2.0.1.0 - Production on Mon Sep 26 14:33:45 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
EXP-00056: ORACLE error 12154 encountered
ORA-12154: TNS:could not resolve the connect identifier specified
EXP-00000: Export terminated unsuccessfully
導(dǎo)出報(bào)錯(cuò),然后進(jìn)行確定Oracle實(shí)例是否是test,查看
[oracle@aliyun_test admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL11G =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = aliyun_test)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl11g.us.oracle.com)
)
)
Oracle實(shí)例是ORCL11G,于是重新導(dǎo)出
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g tables=emp file=/oracle/test/scott_emp.dmp
Export: Release 11.2.0.1.0 - Production on Mon Sep 26 14:38:11 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table EMP 14 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
[oracle@aliyun_test oracle]$ ll /oracle/test/scott_emp.dmp
-rw-r--r-- 1 oracle oinstall 16384 Sep 26 14:38 /oracle/test/scott_emp.dmp
導(dǎo)出多張表
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g tables=emp,dept file=/oracle/test/scott_emp_dept.dmp
Export: Release 11.2.0.1.0 - Production on Mon Sep 26 15:10:05 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table EMP 14 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
. . exporting table DEPT 4 rows exported
EXP-00091: Exporting questionable statistics. 這里出現(xiàn)警告信息,查出是字符集的問(wèn)題
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
字符集不匹配導(dǎo)致的,首先查詢數(shù)據(jù)庫(kù)的字符集
SQL> select sys_context('userenv','language') from dual;
SYS_CONTEXT('USERENV','LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
然后再在設(shè)置與之相同的字符集
[oracle@aliyun_test oracle]$ export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
然后再導(dǎo)出多張表的數(shù)據(jù)
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g tables=emp,dept file=/oracle/test/scott_emp_dept.dmp
Export: Release 11.2.0.1.0 - Production on Mon Sep 26 15:11:56 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table EMP 14 rows exported
. . exporting table DEPT 4 rows exported
Export terminated successfully without warnings.
發(fā)現(xiàn)警告消失了,成功解決警告信息
上述執(zhí)行的是Scott用戶導(dǎo)出自己的表,下面介紹用system用戶來(lái)導(dǎo)出scott用戶的表
[oracle@aliyun_test oracle]$ exp userid=system/redhat@orcl11g tables=scott.emp file=/oracle/test/system_emp.dmp
Export: Release 11.2.0.1.0 - Production on Mon Sep 26 15:17:54 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
About to export specified tables via Conventional Path ...
Current user changed to SCOTT
. . exporting table EMP 14 rows exported
Export terminated successfully without warnings.
只需要修改相應(yīng)的表信息就行
導(dǎo)出表的結(jié)構(gòu),只導(dǎo)出結(jié)構(gòu)
3、導(dǎo)出表的結(jié)構(gòu)
exp userid=scott/redhat@orcl11g tables=emp file=/oracle/test/emp_table.dmp rows=n
4、使用直接導(dǎo)出方式
exp userid=scott/redhat@ocrl11g tables=emp file=/oracle/test/emp_direct.dmp direct=y
這種方式比默認(rèn)的常規(guī)方式速度要快,當(dāng)數(shù)據(jù)量大時(shí),可以考慮使用此種方法
這種方法需要數(shù)據(jù)庫(kù)的字符集和客戶端的字符集完全一致,否則會(huì)報(bào)錯(cuò)
導(dǎo)出方案
導(dǎo)出方案是指使用export工具導(dǎo)出一個(gè)方案或是多個(gè)方案中的所有對(duì)象(表、視圖、索引等等)和數(shù)據(jù),并將它存放到文件中
1、導(dǎo)出自己的方案
[oracle@aliyun_test oracle]$ exp userid=scott/redhat@orcl11g owner=scott file=/oracle/test/schema_scott.dmp
Export: Release 11.2.0.1.0 - Production on Mon Sep 26 15:22:27 2016
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in AL32UTF8 character set and UTF8 NCHAR character set
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SCOTT
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SCOTT
About to export SCOTT's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SCOTT's tables via Conventional Path ...
. . exporting table DEPT 4 rows exported
. . exporting table EMP 14 rows exported
. . exporting table SALGRADE 5 rows exported
. . exporting table STUDENT 0 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.
2、導(dǎo)出其他的方案
如果用戶要導(dǎo)出其他方案,則需要dba的權(quán)限或是exp_full_database的權(quán)限,例如用system用戶
就可以導(dǎo)出任何方案
exp userid=system/redhat@orcl11g owner=system,scott file=/oracle/test/system_scott.dmp
示例表示使用system用戶不能導(dǎo)出sys的schema
導(dǎo)出整個(gè)數(shù)據(jù)庫(kù)
導(dǎo)出數(shù)據(jù)庫(kù)是指利用export導(dǎo)出所有數(shù)據(jù)庫(kù)中的對(duì)象及數(shù)據(jù),要求該用戶具有dba的權(quán)限
或者是exp_full_database權(quán)限
exp userid=system/redhat@orcl11g full=y inctype=comlete file=/oracle/test/full_oracle.dmp
導(dǎo)入表
1、導(dǎo)入表
imp userid=scott/redhat@orcl11g tables=emp file=
模擬刪除一張表,然后進(jìn)行導(dǎo)出數(shù)據(jù)?
[oracle@oracle11g ~]$ exp userid=scott/redhat@orcl11g tables=student
file=/oracle/test/student.dmp
SQL> drop table student;
Table dropped
SQL> desc student;
Object student does not exist
然后imp進(jìn)行導(dǎo)入數(shù)據(jù)
$ imp userid=scott/redhat@orcl11g tables=student file=/oracle/test/student.dmp
最后查看表是否成功導(dǎo)入?
SQL> desc student;
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
XH NUMBER(4) Y
XM VARCHAR2(20) Y
SEX CHAR(2) Y
SAL NUMBER(7,2) Y
BIRTHDAY DATE Y
成功導(dǎo)入表數(shù)據(jù)
2、用system執(zhí)行導(dǎo)入數(shù)據(jù)
模擬刪除
SQL> drop table student;
Table dropped
然后導(dǎo)入表數(shù)據(jù)
$ imp userid=system/redhat@orcl11g tables=student file=/oracle/test/student.dmp touser=scott
然后查看
SQL> desc student;
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
XH NUMBER(4) Y
XM VARCHAR2(20) Y
SEX CHAR(2) Y
SAL NUMBER(7,2) Y
BIRTHDAY DATE Y
3、導(dǎo)入表的結(jié)構(gòu)
只導(dǎo)入表的結(jié)構(gòu)而不導(dǎo)入數(shù)據(jù)
imp userid=scott/redhat@orcl11g tables=emp file= rows=n
4、導(dǎo)入數(shù)據(jù)
如果表的對(duì)象已經(jīng)存在,那么就可以只導(dǎo)入數(shù)據(jù),無(wú)需導(dǎo)入對(duì)象
imp userid=scott/redhat@orcl11g tables=emp file= ignore=y
導(dǎo)入方案
導(dǎo)入方案是指使用import工具將文件中的對(duì)象和數(shù)據(jù)導(dǎo)入到一個(gè)或多個(gè)方案中
如果要導(dǎo)入其他用戶的方案,要求用戶具有dba的權(quán)限,或者是imp_full_database的權(quán)限
1、導(dǎo)入自身的方案
imp userid=scott/redhat@orcl11g file=/oracle/test/schema_scott.dmp
2、導(dǎo)入其他用戶的方案(利用system用戶進(jìn)行操作)
imp userid=system/redhat@orcl11g file=/oracle/test/schema_system_scott.dmp fromuser=system touser=scott
導(dǎo)入數(shù)據(jù)庫(kù)
在默認(rèn)情況下,當(dāng)導(dǎo)入數(shù)據(jù)庫(kù)時(shí),會(huì)導(dǎo)入所有結(jié)構(gòu)和數(shù)據(jù)
imp userid=system/redhat full=y file=/oracle/test/database.dmp
網(wǎng)站欄目:Oracle之管理以及exp、imp的使用
瀏覽路徑:http://www.rwnh.cn/article44/gpoche.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、小程序開(kāi)發(fā)、外貿(mào)建站、電子商務(wù)、、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)