Next Previous Contents

3. 建立一个资料库

Oracle 伺服器现已安装了,我们需要建立一个资料库来测试它。

如果你使用 Oracle 7.2.x 或之前版本,请阅读下面的疑难排解部分。

3.1 建立初始档 (Initialisation File)

$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

3.2 建立资料库安装命令稿

$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

3.3 执行资料库的安装安令稿

开始 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.

3.4 启动资料库

开始时,我们要亲手启动资料库(我们稍後会把这工件自动化)。要启动 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.

3.5 停止资料库

先旨声明,在未关闭一个 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.

3.6 建立内定用户 (Default User)

在建立资料库时,会自动产生两个特别的用户:


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 资料库。如果你只会从这部电脑连接到这资料库,而不会从其他地方,你可休息了!

不过,如果你像大部分人般想设定网络软件使你可以从其他电脑连接,请继续读下去。


Next Previous Contents