命令行创建数据库

1. 根据模板配置创建参数文件

export ORACLE_SID=BOOBOO
mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID
mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump
mkdir -p $ORACLE_BASE/flash_recovery_area
grep -v '^#\|^$' $ORACLE_HOME/dbs/init.ora | sed "s/\(ORCL\|orcl\)/${ORACLE_SID}/;s/<ORACLE_BASE>/\$ORACLE_BASE/;s@ora_control1@\$ORACLE_BASE/oradata/${ORACLE_SID}/ora_control1.ctl@;s@ora_control2@\$ORACLE_BASE/oradata/${ORACLE_SID}/ora_control2.ctl@" > $ORACLE_HOME/dbs/init${ORACLE_SID}.ora

练习

[oracle@db ~]$ cd $ORACLE_HOME/dbs
[oracle@db dbs]$ pwd
/alidata/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@db dbs]$ mkdir -p $ORACLE_BASE/oradata/$ORACLE_SID
[oracle@db dbs]$ mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump
[oracle@db dbs]$ mkdir -p $ORACLE_BASE/flash_recovery_area
[oracle@db dbs]$ grep -v '^#\|^$' $ORACLE_HOME/dbs/init.ora | sed "s/\(ORCL\|orcl\)/${ORACLE_SID}/;s/<ORACLE_BASE>/\$ORACLE_BASE/;s@ora_control1@\$ORACLE_BASE/oradata/${ORACLE_SID}/ora_control1.ctl@;s@ora_control2@\$ORACLE_BASE/oradata/${ORACLE_SID}/ora_control2.ctl@" > $ORACLE_HOME/dbs/init${ORACLE_SID}.ora
[oracle@db dbs]$ cat initBOOBOO.ora
db_name='BOOBOO'
memory_target=1G
processes = 150
audit_file_dest='$ORACLE_BASE/admin/BOOBOO/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='$ORACLE_BASE/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='$ORACLE_BASE'
dispatchers='(PROTOCOL=TCP) (SERVICE=BOOBOOXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
control_files = ($ORACLE_BASE/oradata/BOOBOO/ora_control1.ctl, $ORACLE_BASE/oradata/BOOBOO/ora_control2.ctl)
compatible ='11.2.0'

2. 创建口令文件

orapwd file=orapw$ORACLE_SID password=oracle entries=30

练习

[oracle@db dbs]$ orapwd file=orapw$ORACLE_SID password=oracle entries=30
[oracle@db dbs]$ ll
total 16
-rw-r--r-- 1 oracle oinstall 530 Apr 9 16:45 initBOOBOO.ora
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r----- 1 oracle oinstall 5120 Apr 9 16:48 orapwBOOBOO
[oracle@db dbs]$ cat orapwBOOBOO
]\[ZORACLE Remote Password fileNTERNAAB27B53EDC5FEF41?9?W???1Dy?!?K?A:2?|?LSYS8A8

3. 创建pfile并启动到nomount状态

echo "create spfile from pfile" | sqlplus / as sysdba
echo "startup nomount" | sqlplus / as sysdba

练习

[oracle@db dbs]$ echo $ORACLE_SID
ORCL
[oracle@db dbs]$ sed -i 's/ORCL/BOOBOO/' ~/.bash_profile
[oracle@db dbs]$ source ~/.bash_profile
[oracle@db dbs]$ echo $ORACLE_SID
BOOBOO
[oracle@db dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Apr 9 16:54:02 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile;
File created.

[oracle@db dbs]$ ll
total 20
-rw-r--r-- 1 oracle oinstall 530 Apr 9 16:45 initBOOBOO.ora
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r----- 1 oracle oinstall 5120 Apr 9 16:48 orapwBOOBOO
-rw-r----- 1 oracle oinstall 2560 Apr 9 16:54 spfileBOOBOO.ora

[oracle@db dbs]$ echo "startup nomount" | sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Apr 9 16:58:36 2019

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 671089544 bytes
Database Buffers 390070272 bytes
Redo Buffers 5517312 bytes
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

4. 创建数据库

从官方文档中粘贴建库语句,修改制作建库脚本

[oracle@db dbs]$ cat createdb.sql
CREATE DATABASE BOOBOO
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('/alidata/app/oracle/oradata/BOOBOO/redo01a.log','/alidata/app/oracle/oradata/BOOBOO/redo01b.log') SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/alidata/app/oracle/oradata/BOOBOO/redo02a.log','/alidata/app/oracle/oradata/BOOBOO/redo02b.log') SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/alidata/app/oracle/oradata/BOOBOO/redo03a.log','/alidata/app/oracle/oradata/BOOBOO/redo03b.log') SIZE 100M BLOCKSIZE 512
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/alidata/app/oracle/oradata/BOOBOO/system01.dbf' SIZE 325M REUSE
SYSAUX DATAFILE '/alidata/app/oracle/oradata/BOOBOO/sysaux01.dbf' SIZE 325M REUSE
DEFAULT TABLESPACE users
DATAFILE '/alidata/app/oracle/oradata/BOOBOO/users01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE temp
TEMPFILE '/alidata/app/oracle/oradata/BOOBOO/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs1
DATAFILE '/alidata/app/oracle/oradata/BOOBOO/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

数据库中执行建库脚本:

SQL> @createdb.sql
Database created.

5. 执行生成数据字典信息的脚本并执行

[oracle@db dbs]$ vim 1.sql
@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
conn system/oracle
@?/sqlplus/admin/pupbld.sql

sqlplus / as sysdba
> @1.sql

[oracle@db dbs]$ ll
total 36
-rw-r--r-- 1 oracle oinstall 101 Apr 10 12:17 1.sql
-rw-r--r-- 1 oracle oinstall 1266 Apr 10 11:56 createdb.sql
-rw-rw---- 1 oracle oinstall 1544 Apr 10 12:16 hc_BOOBOO.dat
-rw-r--r-- 1 oracle oinstall 530 Apr 9 18:12 initBOOBOO.ora
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r----- 1 oracle oinstall 24 Apr 10 12:16 lkBOOBOO
-rw-r----- 1 oracle oinstall 5120 Apr 10 12:12 orapwBOOBOO
-rw-r----- 1 oracle oinstall 2560 Apr 10 12:18 spfileBOOBOO.ora

6. 安装插件rlwrap

[root@db ~]# yum list|grep rlwrap
rlwrap.x86_64 0.42-1.el6 epel
[root@db ~]# yum install -y rlwrap