Oracle 伺服器現已安裝了,我們需要建立一個資料庫來測試它。
如果你使用 Oracle 7.2.x 或之前版本,請閱讀下面的疑難排解部分。
把 $ORACLE_HOME/dbs/init.ora
抄到 $ORACLE_HOME/dbs/initorcl.ora
:
$ cd $ORACLE_HOME/dbs
$ cp init.ora initorcl.ora
加上以下數行:
db_name = orcl
COMPATIBLE=7.3.3.0.0
在 $ORACLE_HOME/dbs
目錄下建立一個名為 makedb.sql 的命令稿檔:
connect internal
startup nomount
set echo on
spool makedb.log
create database orcl
maxinstances 1
maxlogfiles 8
datafile '$ORACLE_HOME/dbs/orcl_syst_01.dbf' size 40M reuse
logfile
'$ORACLE_HOME/dbs/orcl_redo_01.dbf' size 1M reuse,
'$ORACLE_HOME/dbs/orcl_redo_02.dbf' size 1M reuse,
'$ORACLE_HOME/dbs/orcl_redo_03.dbf' size 1M reuse;
@$ORACLE_HOME/rdbms/admin/catalog.sql
create tablespace rollback
datafile '$ORACLE_HOME/dbs/orcl_roll_01.dbf' size 8.5M reuse;
create tablespace temp
datafile '$ORACLE_HOME/dbs/orcl_temp_01.dbf' size 5M reuse
temporary;
create tablespace users
datafile '$ORACLE_HOME/dbs/orcl_user_01.dbf' size 10M reuse;
create rollback segment r1 tablespace rollback
storage ( optimal 5M );
alter rollback segment r1 online;
connect system/manager
@$ORACLE_HOME/rdbms/admin/catdbsyn.sql
connect internal
@$ORACLE_HOME/rdbms/admin/catproc.sql
connect system/manager
@$ORACLE_HOME/sqlplus/admin/pupbld.sql
spool off
exit
開始 svrmgrl
及執行命令稿︰
$ cd $ORACLE_HOME/dbs
$ svrmgrl
Oracle Server Manager Release 2.3.3.0.0 - Production
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle7 Server Release 7.3.3.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
SVRMGR> connect internal
Connected.
SVRMGR> startup nomount
ORACLE instance started.
Total System Global Area 4313312 bytes
Fixed Size 41876 bytes
Variable Size 4140364 bytes
Database Buffers 122880 bytes
Redo Buffers 8192 bytes
SVRMGR> @makedb
<loads of messages>
SVRMGR> exit
Server Manager complete.
開始時,我們要親手啟動資料庫(我們稍後會把這工件自動化)。要啟動 Oracle 的資料庫,我們要來內部連接 (connected internally) 了的情況下執行 startup
指令:
$ svrmgrl
Oracle Server Manager Release 2.3.3.0.0 - Production
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle7 Server Release 7.3.3.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
SVRMGR> connect internal
Connected.
SVRMGR> startup
ORACLE instance started.
Total System Global Area 4313316 bytes
Fixed Size 41876 bytes
Variable Size 4140368 bytes
Database Buffers 122880 bytes
Redo Buffers 8192 bytes
Database mounted.
Database opened.
SVRMGR> exit
Server Manager complete.
先旨聲明,在未關閉一個 Oracle 資料庫的情況下重新啟動 Linux 很有可能會使資料庫損毀。
因此,在我們執行 Linux 的 shutdown
指令前最好先關閉資料庫:
$ svrmgrl
Oracle Server Manager Release 2.3.3.0.0 - Production
Copyright (c) Oracle Corporation 1994, 1995. All rights reserved.
Oracle7 Server Release 7.3.3.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
SVRMGR> connect internal
Connected.
SVRMGR> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SVRMGR> exit
Server Manager complete.
在建立資料庫時,會自動產生兩個特別的用戶:
Username Password
SYSTEM MANAGER
SYS change_on_install
這些用戶通常是用來保存標準的資料字典 (data dictionary) 資料在資料庫中。盡快把密碼修改是一個好主意。
可以這樣做:
sqlplus system/manager
SQL*Plus: Release 3.3.3.0.0 - Production on Sat Feb 21 12:43:33 1998
Copyright (c) Oracle Corporation 1979, 1996. All rights reserved.
Connected to:
Oracle7 Server Release 7.3.3.0.0 - Production Release
SQL> alter user system identified by <newpassword>;
User altered.
SQL> alter user sys identified by <newpassword>;
User altered.
SQL> exit;
Disconnected from Oracle7 Server Release 7.3.3.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
用戶 system/manager
就如 UNIX 中的 root
,因此我們要建立另一個權力較少的用戶以防損失。(記著要先開啟資料庫才建立用戶。)
連接到 SQL*Plus 及建立用戶:
$ sqlplus system/manager
SQL*Plus: Release 3.3.3.0.0 - Production on Sat Feb 21 12:43:33 1998
Copyright (c) Oracle Corporation 1979, 1996. All rights reserved.
Connected to:
Oracle7 Server Release 7.3.3.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
SQL> create user <user> identified by <psw>
2 default tablespace users
3 temporary tablespace temp;
User created.
SQL> grant connect, resource to <user>
Grant succeeded.
SQL> exit
Disconnected from Oracle7 Server Release 7.3.3.0.0 - Production Release
PL/SQL Release 2.3.3.0.0 - Production
系統中已有一個新用戶,你可以用他來試用新系統。要簽入 Oracle 資料庫:
$ sqlplus <user>/<password>
如果這在沒有錯誤訊息的情況下完成,你已有一個運作中的 Oracle 資料庫。如果你只會從這部電腦連接到這資料庫,而不會從其他地方,你可休息了!
不過,如果你像大部分人般想設定網絡軟件使你可以從其他電腦連接,請繼續讀下去。