1、創建目錄
mkdir d:\Oracle\product\10.1.0\database
mkdir e:\Oracle\admin\Ora10g\bdump
mkdir e:\Oracle\admin\Ora10g\cdump
mkdir e:\Oracle\admin\Ora10g\create
mkdir e:\Oracle\admin\Ora10g\pfile
mkdir e:\Oracle\admin\Ora10g\udump
mkdir e:\Oracle\Flash_recovery_area
mkdir e:\Oracle\oradata
mkdir e:\Oracle\oradata\Ora10g
2、生成Windows服務,創建密碼文件,在cmd命令下運行
set ORACLE_SID=dbca --綠色部分設置Oracle 實例名為 為ora10g
d:\oracle\product\10.1.0\DB_1\bin\oradim.exe -new -sid ORA10G -startmode manual -spfile d:\Oracle\product\10.1.0\DB_1\bin\oradim.exe -edit -sid ORA10G -startmode a -spfile
--創建一個實例名為dbca 並且有手動啟動方式改為自動啟動
d:\oracle\product\10.1.0\DB_1\bin\orapwd.exe file=d:\Oracle\product\10.1.0\db_1\PWDOra10g.ora password=sysPassWord force=y
--用Oracle自帶的orapwd 為sys用戶創建一個默認的密碼為sysPassWord
3、執行創建數據庫腳本
D:\oracle\ora92\bin\sqlplus /nolog @D:\Oracle\admin\dbca\scripts\CreateDB.sql
D:\oracle\ora92\bin\sqlplus /nolog @D:\Oracle\admin\dbca\scripts\CreateDBFiles.sql
D:\oracle\ora92\bin\sqlplus /nolog @D:\Oracle\admin\dbca\scripts\CreateDBCatalog.sql
D:\oracle\ora92\bin\sqlplus /nolog @D:\Oracle\admin\dbca\scripts\postDBCreation.sql
--黑體部分就是創建數據庫要調用的腳本
第一 CreateDB.sql
connect SYS/change_on_install as SYSDBA --這是剛剛我們設置的密碼以sysdba身份連接到數據庫
connect SYS/change_on_install as SYSDBA --這是剛剛我們設置的密碼以sysdba身份連接到數據庫
set echo on
spool D:\Oracle\ora92\assistants\dbca\logs\CreateDB.log 寫日志
startup nomount pfile="D:\Oracle\admin\dbca\scripts\init.ora"; 調用參數文件 啟動數據庫到只裝載實例階段
CREATE DATABASE dbca
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 100 --控制文件記錄的相關最大日志數,日志組,最大數據文件數等限制
DATAFILE 'D:\Oracle\oradata\dbca\system01.dbf' SIZE 250M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE 'D:\Oracle\oradata\dbca\temp01.dbf' SIZE 40M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE "UNDOTBS1" DATAFILE 'D:\Oracle\oradata\dbca\undotbs01.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:\Oracle\oradata\dbca\redo01.log') SIZE 102400K,
GROUP 2 ('D:\Oracle\oradata\dbca\redo02.log') SIZE 102400K,
GROUP 3 ('D:\Oracle\oradata\dbca\redo03.log') SIZE 102400K; --創建日志文件租和成員
spool off
exit;
第二.CreateDBFiles.sql
connect SYS/change_on_install as SYSDBA
set echo on
spool D:\Oracle\ora92\assistants\dbca\logs\CreateDBFiles.log
CREATE TABLESPACE "INDX" LOGGING DATAFILE 'D:\Oracle\oradata\dbca\indx01.dbf' SIZE 25M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
CREATE TABLESPACE "TOOLS" LOGGING DATAFILE 'D:\Oracle\oradata\dbca\tools01.dbf' SIZE 10M REUSE AUTOEXTEND ON NEXT 320K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
CREATE TABLESPACE "USERS" LOGGING DATAFILE 'D:\Oracle\oradata\dbca\users01.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:\Oracle\ora92\assistants\dbca\logs\CreateDBCatalog.log
@D:\Oracle\ora92\rdbms\admin\catalog.sql;
@D:\Oracle\ora92\rdbms\admin\catexp7.sql;
@D:\Oracle\ora92\rdbms\admin\catblock.sql;
@D:\Oracle\ora92\rdbms\admin\catproc.sql;
@D:\Oracle\ora92\rdbms\admin\catoctk.sql;
@D:\Oracle\ora92\rdbms\admin\owminst.plb;
connect SYSTEM/manager
@D:\Oracle\ora92\sqlplus\admin\pupbld.sql;
connect SYSTEM/manager
set echo on
spool D:\Oracle\ora92\assistants\dbca\logs\sqlPlusHelp.log
@D:\Oracle\ora92\sqlplus\admin\help\hlpbld.sql helpus.sql;
spool off
spool off
exit;
第四: postDBCreation.sql
connect SYS/change_on_install as SYSDBA
set echo on
spool D:\Oracle\ora92\assistants\dbca\logs\postDBCreation.log
@D:\Oracle\ora92\rdbms\admin\utlrp.sql; --編譯相關視圖,包對象等
shutdown ; --關閉數據庫
connect SYS/change_on_install as SYSDBA
set echo on
spool D:\Oracle\ora92\assistants\dbca\logs\postDBCreation.log
create spfile='D:\oracle\ora92\database\spfiledbca.ora' FROM pfile='D:\Oracle\admin\dbca\scripts\init.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