拷貝了控制文件到指定目錄,執行:html
alter system set control_files='/u01/app/oradata/controlfile/control01.ctl','/u01/app/oradata/controlfile/control02.ctl' scope=spfile;sql
後啓動報告控制文件錯誤數據庫
後來使用oracle用戶拷貝文件後成功,應該是文件訪問權限問題。安全
有文章說編輯/orcl/app/oracle/product/12.1.0/db_1/bindbstart,將ORACLE_HOME_LISTNER=$1修改爲 ORACLE_HOME_LISTNER=$ORACLE_HOME 前提是$ORACLE_HOME環境設置正確
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/dbhome_1服務器
我看了一下,其實dbstart中接收傳入參數,因此啓動時傳入$ORACLE_HOME便可網絡
Dbstart $ORACLE_HOMEsession
這樣編輯/etc/oratab文件oracle
dbca建庫時都會自動建立/etc/oratab文件app
將orcl:/orcl/oracle/product/12.1.0/db_1:Ndom
修改爲 orcl:/orcl/oracle/product/12.1.0/db_1:Y
若是沒有這個文件則
以root身份進入$ORACLE_HOME
執行./root.sh
編輯/etc/rc.d/rc.local啓動文件,添加數據庫啓動腳本dbstart
su oracle -lc "/orcl/app/oracle/product/12.1.0/db_1/bin/lsnrctl start"
su oracle -lc "/orcl/app/oracle/product/12.1.0/db_1/bin/dbstart $ORACLE_HOME"
su oracle -lc "/orcl/app/oracle/product/12.1.0/db_1/bin/emctl start dbconsole"
注意,oracle 12c中沒有emctl了。
發現不生效,再一查,發現:
在CentOS7中,官方將/etc/rc.d/rc.local 的開機自啓的權限禁止掉了,他爲了兼容性,設置了這個,可是並不默認啓動.若是須要的話.執行如下代碼
chmod +x /etc/rc.d/rc.local
將文件受權,這樣他就能夠開機自啓了.
官方在新版上推薦使用systemcd進行自啓動.
查看防火牆狀態
firewall-cmd --state
中止firewall
systemctl stop firewalld.service
禁止firewall開機啓動
systemctl disable firewalld.service
[root@oracle12c ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.112 oracle12c
[oracle@oracle12c admin]$ cat listener.ora
# listener.ora Network Configuration File: /orcl/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle12c)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /orcl/app
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
)
[oracle@oracle12c admin]$ cat listener.ora
# listener.ora Network Configuration File: /orcl/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle12c)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /orcl/app
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
)
中止:lsnrctl stop
啓動:lsnrctl start
查看:lsnrctl status
重載:lsnrctl reload
[oracle@oracle12c admin]$ lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 17-MAY-2019 18:40:14
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle12c)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 17-MAY-2019 18:33:04
Uptime 0 days 0 hr. 7 min. 9 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /orcl/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File /orcl/app/diag/tnslsnr/oracle12c/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle12c)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
1. sqlplus / as sysdba
操做系統認證,不須要數據庫服務器啓動listener,也不須要數據庫服務器處於可用狀態。好比咱們想要啓動數據庫就能夠用這種方式進入
sqlplus,而後經過startup命令來啓動。
2. sqlplus username/password
鏈接本機數據庫,不須要數據庫服務器的listener進程,可是因爲須要用戶名密碼的認證,所以須要數據庫服務器處於可用狀態才行。
3. sqlplus usernaem/password@orcl
經過網絡鏈接,這是須要數據庫服務器的listener處於監聽狀態。此時創建一個鏈接的大體步驟以下
a. 查詢sqlnet.ora,看看名稱的解析方式,默認是TNSNAME
b. 查詢tnsnames.ora文件,從裏邊找orcl的記錄,而且找到數據庫服務器的主機名或者IP,端口和service_name
c. 若是服務器listener進程沒有問題的話,創建與listener進程的鏈接。
d. 根據不一樣的服務器模式如專用服務器模式或者共享服務器模式,listener採起接下去的動做。默認是專用服務器模式,沒有問題的話客戶端
就鏈接上了數據庫的server process。
e. 這時鏈接已經創建,能夠操做數據庫了。
4.sqlplus username/password@//host:port/sid
用sqlplus遠程鏈接oracle命令(例:sqlplus risenet/1@//192.168.130.99:1521/risenet)
一個實例中的臨時表空間能夠有多個,只能有一個是活動的
還原表空間能夠有多個,但只能有一個是活動的。能夠切換活動的還原表空間。
見外部文件單獨記錄。
表空間能夠有多個物理文件,若是一個滿了,會自動往第二個文件上寫嗎?若是第一個設置成了自動增加呢?
多數據庫狀況下的數據庫自啓動、監聽
orcl:/orcl/app/oracle/product/12.1.0/db_1:Y
myorcl:/orcl/app/oracle/product/12.1.0/db_1:Y
[oracle@oracle12c admin]$ cat listener.ora
# listener.ora Network Configuration File: /orcl/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle12c)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /orcl/app
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
(SID_DESC =
(GLOBAL_DBNAME = myorcl)
(SID_NAME = myorcl)
)
)
[oracle@oracle12c admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /orcl/app/oracle/product/12.1.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle12c)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
MYORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle12c)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = myorcl)
)
)
SQL> select constraint_name,table_name,constraint_type,status,deferrable,deferred,validated from dba_constraints where owner='SCOTT';
Deferrable和deferred,搞不清……
建立用戶
Create user xxh identified by 123;
修改權限
Alter user xxh indentified by 123456;
受權
Grant create session,select any table,create table,create view to xxh;
GRANT RESOURCE TO xxh;
oracle中如何賦予該用戶CONNECT、RESOURCE、DBA身份
grant connect,resource,dba to user;
CONNECT角色: --是授予最終用戶的典型權利,最基本的
CREATE SESSION --創建會話
RESOURCE角色: --是授予開發人員的
CREATE CLUSTER --創建聚簇
CREATE PROCEDURE --創建過程
CREATE SEQUENCE --創建序列
CREATE TABLE --建表
CREATE TRIGGER --創建觸發器
CREATE TYPE --創建類型
CREATE OPERATOR --建立操做者
CREATE INDEXTYPE --建立索引類型
CREATE TABLE --建立表
DBA角色: --是授予數據庫維護人員的
角色的口令
對於 oracle裏角色的密碼,就是 當你 SET Role 啓用角色的時候,若是這個 角色是有密碼的, 你須要輸入 角色的密碼, 來啓用這個角色。
由於測試環境創建了多個表空間,而且移動了控制文件,表空間等也放在了不一樣的地方,在shutdown immediate後拷貝數據庫文件、參數文件等時忘記了拷貝控制文件,結果在拷貝文件後刪除原庫數據,而後再把備份過的文件拷貝回原位置後,試圖啓動數據庫startup時報告錯誤。因而先startup mount,而後執行:
SQL> startup mount
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oradata/orcl/system01.dbf'
若是此時執行:
SQL> recover datafile '/u01/app/oradata/orcl/system01.dbf';
ORA-00283: recovery session canceled due to errors
ORA-00322: log 2 of thread 1 is not current copy
ORA-00312: online log 2 thread 1: '/u01/app/oradata/orcl/redo02.log'
由於測試環境沒有須要重作的,因而:
SQL> alter database clear unarchived logfile group 2;
Database altered.
此時再逐個執行有問題的文件:
SQL> recover datafile '/u01/app/oradata/orcl/system01.dbf';
Media recovery complete.
…
最後
SQL> alter database open;
Database altered.
不清楚這種狀況是否是控制文件沒有備份引發的,是否是有更好的恢復辦法,這樣有什麼問題。
創建了一個導出配置文件:
[oracle@DB ~]$ cat scott_par.txt
DIRECTORY=DATA_PUMP_DIR
tables=emp_dump,dept_dump
DUMPFILE=SCOTT.dump
而後在導出時出現錯誤:
[oracle@DB ~]$ expdp scott/tiger parfile=scott_par.txt
Export: Release 11.2.0.4.0 - Production on Fri May 24 17:40:07 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39087: directory name DATA_PUMP_DIR is invalid
查看設置:
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME DIRECTORY_PATH
---------- ------------------------------ --------------------------------------------------------------------------------
SYS LOG_FILE_DIR /u01/app/cfgtoollogs/dbca/orcl/
SYS DATA_FILE_DIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/sales_history/
SYS SUBDIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/order_entry//2002/Sep
SYS MEDIA_DIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/product_media/
SYS SS_OE_XMLDIR /u01/app/oracle/product/11.2.0/dbhome_1/demo/schema/order_entry/
SYS XMLDIR /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/xml
SYS ORACLE_OCM_CONFIG_DIR /u01/app/oracle/product/11.2.0/dbhome_1/ccr/hosts/DB/state
SYS DATA_PUMP_DIR /u01/app/admin/orcl/dpdump/
SYS ORACLE_OCM_CONFIG_DIR2 /u01/app/oracle/product/11.2.0/dbhome_1/ccr/state
9 rows selected.
當前目錄存在,判斷是權限問題。
受權:
SQL> conn / as sysdba
Connected.
SQL> grant read,write on directory DATA_PUMP_DIR to scott;
Grant succeeded.
而後執行導出,成功。
[oracle@DB ~]$ expdp scott/tiger parfile=scott_par.txt
Export: Release 11.2.0.4.0 - Production on Fri May 24 17:41:52 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** parfile=scott_par.txt
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."DEPT_DUMP" 5.937 KB 4 rows
. . exported "SCOTT"."EMP_DUMP" 8.570 KB 14 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
/u01/app/admin/orcl/dpdump/SCOTT.dump
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at Fri May 24 17:41:58 2019 elapsed 0 00:00:04
導入到其餘用戶
創建導出配置:
[oracle@DB ~]$ cat exp_par.txt
DIRECTORY=DATA_PUMP_DIR
SCHEMAS=scott
DUMPFILE=schema-scott.dat
EXCLUDE=PACKAGE
EXCLUDE=VIEWE
EXCLUDE=TABLE:"LIKE '%DUMP'"
創建導入配置:
[oracle@DB ~]$ cat imp_par.txt
DIRECTORY=DATA_PUMP_DIR
DUMPFILE=schema-scott.dat
REMAP_SCHEMA=SCOTT:IMPTEST
REMAP_TABLESPACE=USERS:PIONEER_DATA
注意,REMAP_SCHEMA=SCOTT:IMPTEST中的IMPTEST將會在數據庫中創建新的用戶IMPTEST,若是設置爲已存在用戶,好比PJINLIAN,則會導入到現用戶下。
導出:
[oracle@DB ~]$ expdp system/oracle parfile=exp_par.txt
Export: Release 11.2.0.4.0 - Production on Fri May 24 18:21:56 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** parfile=exp_par.txt
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 192 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."DEPT" 5.929 KB 4 rows
. . exported "SCOTT"."EMP" 8.562 KB 14 rows
. . exported "SCOTT"."SALGRADE" 5.859 KB 5 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/u01/app/admin/orcl/dpdump/schema-scott.dat
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Fri May 24 18:22:08 2019 elapsed 0 00:00:12
導入:
[oracle@DB ~]$ impdp system/oracle parfile=imp_par.txt
"imp_par.txt"
Import: Release 11.2.0.4.0 - Production on Fri May 24 18:27:50 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/******** parfile=imp_par.txt
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "IMPTEST"."DEPT" 5.929 KB 4 rows
. . imported "IMPTEST"."EMP" 8.562 KB 14 rows
. . imported "IMPTEST"."SALGRADE" 5.859 KB 5 rows
. . imported "IMPTEST"."BONUS" 0 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Fri May 24 18:27:54 2019 elapsed 0 00:00:03
Oracle中的文件目錄
通常建立directory都是爲了用數據泵導入/導出數據用,其實directory還有不少別的用處。
一、新建directory的語法
CREATE [OR REPLACE] DIRECTORY directory AS 'pathname';
例如:
create or replace directory dump_dir as 'D:\dump\dir'
這樣把目錄d:\dump\dir設置成dump_dir表明的directory
二、查詢有哪些directory
select * from dba_directories
三、賦權
grant read,write on directory dump_dir to user01
四、刪除
drop directory dump_dir