1、創建目錄
mkdir d:oracleproduct10.1.0database
mkdir e:oracleadminOra10gdump
mkdir e:oracleadminOra10gcdump
mkdir e:oracleadminOra10gcreate
mkdir e:oracleadminOra10gpfile
mkdir e:oracleadminOra10gudump
mkdir e:oracleflash_recovery_area
mkdir e:oracleoradata
mkdir e:oracleoradataOra10g
2、生成windows服務,創建密碼文件,在cmd命令下運行
set ORACLE_SID=dbca --綠色部分設置oracle 實例名為 為ora10g
d:oracleproduct10.1.0DB_1inoradim.exe -new -sid ORA10G -startmode manual -spfile d:oracleproduct10.1.0DB_1inoradim.exe -edit -sid ORA10G -startmode a -spfile
--創建一個實例名為dbca 並且有手動啟動方式改為自動啟動
d:oracleproduct10.1.0DB_1inorapwd.exe file=d:oracleproduct10.1.0db_1PWDOra10g.ora password=sysPassword force=y
--用oracle自帶的orapwd 為sys用戶創建一個默認的密碼為sysPassword
3、執行創建數據庫腳本
D:oracleora92insqlplus /nolog @D:oracleadmindbcascriptsCreateDB.sql
D:oracleora92insqlplus /nolog @D:oracleadmindbcascriptsCreateDBFiles.sql
D:oracleora92insqlplus /nolog @D:oracleadmindbcascriptsCreateDBCatalog.sql
D:oracleora92insqlplus /nolog @D:oracleadmindbcascriptspostDBCreation.sql
--黑體部分就是創建數據庫要調用的腳本
第一 CreateDB.sql
connect SYS/change_on_install as SYSDBA --這是剛剛我們設置的密碼以sysdba身份連接到數據庫
connect SYS/change_on_install as SYSDBA --這是剛剛我們設置的密碼以sysdba身份連接到數據庫
set echo on
spool D:oracleora92assistantsdbcalogsCreateDB.log 寫日志
startup nomount pfile="D:oracleadmindbcascriptsinit.ora"; 調用參數文件 啟動數據庫到只裝載實例階段
CREATE DATABASE dbca
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 100 --控制文件記錄的相關最大日志數,日志組,最大數據文件數等限制
DATAFILE 'D:oracleoradatadbcasystem01.dbf' SIZE 250M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE 'D:oracleoradatadbca emp01.dbf' SIZE 40M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE "UNDOTBS1" DATAFILE 'D:oracleoradatadbcaundotbs01.dbf' SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED --創建系統,臨時,回滾 表空間ITPUB個人空間!dJ5l {!i4W r f
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16 --字符集
LOGFILE GROUP 1 ('D:oracleoradatadbca edo01.log') SIZE 102400K,
GROUP 2 ('D:oracleoradatadbca edo02.log') SIZE 102400K,
GROUP 3 ('D:oracleoradatadbca edo03.log') SIZE 102400K; --創建日志文件租和成員
spool off
exit;
第二.CreateDBFiles.sql
connect SYS/change_on_install as SYSDBA
set echo on
spool D:oracleora92assistantsdbcalogsCreateDBFiles.log
CREATE TABLESPACE "INDX" LOGGING DATAFILE 'D:oracleoradatadbcaindx01.dbf' SIZE 25M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
CREATE TABLESPACE "TOOLS" LOGGING DATAFILE 'D:oracleoradatadbca ools01.dbf' SIZE 10M REUSE AUTOEXTEND ON NEXT 320K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
CREATE TABLESPACE "USERS" LOGGING DATAFILE 'D:oracleoradatadbcausers01.dbf' SIZE 25M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ; --創建相關用戶要用到的表空間
spool off
exit;
第三:CreateDBCatalog.sql
--創建system數據字典,存放到system表空間,相關表,視圖等
connect SYS/change_on_install as SYSDBA
set echo on
spool D:oracleora92assistantsdbcalogsCreateDBCatalog.log
@D:oracleora92 dbmsadmincatalog.sql;
@D:oracleora92 dbmsadmincatexp7.sql;
@D:oracleora92 dbmsadmincatblock.sql;
@D:oracleora92 dbmsadmincatproc.sql;
@D:oracleora92 dbmsadmincatoctk.sql;
@D:oracleora92 dbmsadminowminst.plb;
connect SYSTEM/manager
@D:oracleora92sqlplusadminpupbld.sql;
connect SYSTEM/manager
set echo on
spool D:oracleora92assistantsdbcalogssqlPlusHelp.log
@D:oracleora92sqlplusadminhelphlpbld.sql helpus.sql;
spool off
spool off
exit;
第四: postDBCreation.sql
connect SYS/change_on_install as SYSDBA
set echo on
spool D:oracleora92assistantsdbcalogspostDBCreation.log
@D:oracleora92 dbmsadminutlrp.sql; --編譯相關視圖,包對象等
shutdown ; --關閉數據庫
connect SYS/change_on_install as SYSDBA
set echo on
spool D:oracleora92assistantsdbcalogspostDBCreation.log
create spfile='D:oracleora92databasespfiledbca.ora' FROM pfile='D:oracleadmindbcascriptsinit.ora';
--創建服務器參數文件代替文件初始化參數文件,方便有時在不重啟數據庫的情況下可以使參數生效
從上面可以看到spfile文件的存放位置
startup ; --啟動數據庫 ,創建數據庫完成
exit;
從上面可以看出,創建數據庫有以下10個步驟
Step 1: 創建相關trace目錄文件夾
Step 2:創建實例,密碼 啟動方式
Step 3:創建初始化參數文件 init.ora
Step 4: 連接到實例
Step 5: 啟動實例到nomount狀態
Step 6:創建數據庫
Step 7:創建表空間
Step 8: 運行腳本創建數據字典
Step 9: 創建服務器參數文件(這步不是必須的,但oracle建議做這步) 好處會在以後的總結中列出
下面也貼出linux下腳本,和windows下幾乎差不多
#!/bin/sh
mkdir /oradata/ora9i
mkdir /oradata/ora9i/controlfile
mkdir /oradata/ora9i/redofile
mkdir /orasys/oracle/admin
mkdir /orasys/oracle/admin/ora9i
mkdir /orasys/oracle/admin/ora9i/bdump
mkdir /orasys/oracle/admin/ora9i/cdump
mkdir /orasys/oracle/admin/ora9i/create
mkdir /orasys/oracle/admin/ora9i/udump
mkdir /orasys/oracle/admin/ora9i/pfile
cp init.ora /orasys/oracle/product/9.2.0/dbs/.
export ORACLE_BASE=/orasys/oracle
export ORACLE_HOME=$ORACLE_BASE/product/9.2.0
export ORACLE_SID=ora9i
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
echo Add this entry in the oratab: ora9i:/orasys/oracle/product/9.2.0:Y
/orasys/oracle/product/9.2.0/bin/orapwd file=/orasys/oracle/product/9.2.0/dbs/orapwora9i password=change_on_install
/orasys/oracle/product/9.2.0/bin/sqlplus /nolog @/home/oracle/create_script/CreateDB.sql
/orasys/oracle/product/9.2.0/bin/sqlplus /nolog @/home/oracle/create_script/CreateDBFiles.sql
/orasys/oracle/product/9.2.0/bin/sqlplus /nolog @/home/oracle/create_script/CreateDBCatalog.sql
/orasys/oracle/product/9.2.0/bin/sqlplus /nolog @/home/oracle/create_script/postDBCreation.sql