一、修改oracle用户环境变量
[oracle@oracle ~]$ su - oracle
[oracle@oracle ~]$ vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/dbhome_1
export ORACLE_SID=ORACLEDB
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$ORACLE_HOME/bin
export PATH
[oracle@oracle ~]$ source .bash_profile
二、启动监听
[oracle@oracle ~]$ lsnrctl start
三、手工建库
1、创建Oracle数据目录:
1: [oracle@oracle ~]$ mkdir -p $ORACLE_BASE/oradata/ORACLEDB
2: [oracle@oracle ~]$ mkdir -p $ORACLE_BASE/admin/ORACLEDB
3: [oracle@oracle ~]$ mkdir -p $ORACLE_BASE/flash_recovery_area
2、创建Oracle的口令认证
1: [oracle@oracle ~]$ cd $ORACLE_HOME/dbs
2: [oracle@oracle dbs]$ orapwd file=orapwORACLEDB password=oracle entries=30
3、创建初始化参数文件
a、以官方参数文件为模板创建初始化参数文件
1: [oracle@oracle ~]cd $ORACLE_HOME/dbs
2: [oracle@oracle ~]cat init.ora |grep -v ^#|grep -v ^$> initORACLEDB.ora
b、修改初始化参数文件
修改前:
db_name='ORCL'
memory_target=1G
processes = 150
audit_file_dest='<ORACLE_BASE>/admin/orcl/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=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (ora_control1, ora_control2)
compatible ='11.2.0'
在vim末行命令的编辑状态中输入
1: :%s#orcl#ORACLEDB#gi里面替换的orcl的字符串。其中i命令不区分大小写。
2: :%s#ora_control1#/u01/app/oracle/oradata/ORACLEDB/control01.ctl#g替换ora_control1的字符串。
3: :%s#ora_control2#/u01/app/oracle/oradata/ORACLEDB/control02.ctl#g替换ora_control2的字符串。
4: :%s#<ORACLE_BASE>#/u01/app/oracle#g替换<ORACLE_BASE>的字符串。
5: :wq命令保存配置
修改后:
db_name='ORACLEDB'
memory_target=1G
processes = 150
audit_file_dest='/u01/app/oracle/admin/ORACLEDB/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORACLEDBXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (/u01/app/oracle/oradata/ORACLEDB/control01.ctl, /u01/app/oracle/oradata/ORACLEDB/control02.ctl)
compatible ='11.2.0'
4、连接数据库实例
1: 命令文件连接:
2: [oracle@oracle ~]sqlplus sys/oracle as sysdba
3: SYS@>create spfile from pfile;
5、启动实例
1: SYS@>startup nomount
6、在当前目录创建create database语句创建数据库
CREATE DATABASE ORACLEDB
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('/u01/app/oracle/oradata/ORACLEDB/redo01a.log','/u01/app/oracle/oradata/ORACLEDB/redo01b.log') SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/u01/app/oracle/oradata/ORACLEDB/redo02a.log','/u01/app/oracle/oradata/ORACLEDB/redo02b.log') SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/u01/app/oracle/oradata/ORACLEDB/redo03a.log','/u01/app/oracle/oradata/ORACLEDB/redo03b.log') SIZE 100M BLOCKSIZE 512
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/u01/app/oracle/oradata/ORACLEDB/system01.dbf' SIZE 325M REUSE
SYSAUX DATAFILE '/u01/app/oracle/oradata/ORACLEDB/sysaux01.dbf' SIZE 325M REUSE
DEFAULT TABLESPACE users
DATAFILE '/u01/app/oracle/oradata/ORACLEDB/users01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/u01/app/oracle/oradata/ORACLEDB/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs1
DATAFILE '/u01/app/oracle/oradata/ORACLEDB/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
给文件授予权限,并执行脚本:
1: [oracle@oracle dbs]chmod 755 create_database.sql
2: [oracle@oracle dbs]sqlplus / as sysdba
3: SYS@>@create_database.sql
4: Database created.
7、执行脚本并构建数据字典视图
1: [oracle@oracle ~] sqlplus / as sysdba
2: SYS@>@?/rdbms/admin/catalog.sql
3: SYS@>@?/rdbms/admin/catproc.sql
4: SYS@>@?/rdbms/admin/utlrp.sql
8、使用system用户登录,执行脚本
1: [oracle@oracle ~]sqlplus system/oracle
2: SYSTEM@> @?/sqlplus/admin/pupbld.sql
四、验证数据库,是否正常:
1:[oracle@oracle ~]sqlplus / as sysdba
2:SYS@>select INSTANCE_NAME,STATUS from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
OEACLEDB OPEN