在linux系统的oracle下边手动创建数据库:
环境:redhat enterprise linux 5 +oracle10g
手动创建数据库方法:
第一步骤:
我创建的数据库名称是ssh
[oracle@localhost ~]$ su - root
口令:
[root@localhost ~]# useradd -m -g oinstall -G dba oracle11g
[root@localhost ~]# passwd oracle11g
Changing password for user oracle11g.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
给oracle11g赋予执行读取权限
[root@localhost ~]# chown -R oracle11g
install /u01/app/oracle
[root@localhost ~]# chmod -R 775 /u01/app/oracle
修改环境变量:
[root@localhost ~]# su - oracle11g
[oracle11g@localhost ~]$ vi ~/.bash_profile
添加环境变量:
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=ssh
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
保存后使用如下命令,使设置生效:
$ source ~/.bash_profile
2.
使用env命令验证环境变量是否生效
[oracle11g@localhost ~]$ env
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
USER=oracle11g
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36
i=40;33:so=00;35:bd=40;33;01:cd=40;33;01
r=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:
ORACLE_SID=ssh
ORACLE_BASE=/u01/app/oracle
MAIL=/var/spool/mail/oracle11g
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle11g/bin:/u01/app/oracle/product/10.2.0/db_1/bin
INPUTRC=/etc/inputrc
PWD=/home/oracle11g
LANG=zh_CN.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=1
HOME=/home/oracle11g
LOGNAME=oracle11g
LESSOPEN=|/usr/bin/lesspipe.sh %s
DISPLAY=:0.0
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
G_BROKEN_FILENAMES=1
_=/bin/env
3.
调用口令文件创建工具orapwd创建口令文件
orapwd FILE=/u01/app/oracle/product/10.2.0/db_1/dbs/orapssh PASSWORD=123456 ENTRIES=5
4.
创建初始化参数文件PFILE
vi /u01/app/oracle/product/10.2.0/db_1/dbs/initssh.ora2
##############################################################################
# Copyright (c) 1991, 2001, 2002 by Oracle Corporation
##############################################################################
###########################################
# Cache and I/O
###########################################
db_block_size=8192
db_file_multiblock_read_count=16
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_domain=""
db_name='ssh'
###########################################
# Diagnostics and Statistics
###########################################
background_dump_dest=/u01/app/oracle/admin/ssh/bdump
core_dump_dest=/u01/app/oracle/admin/ssh/cdump
user_dump_dest=/u01/app/oracle/admin/ssh/udump
###########################################
# File Configuration
###########################################
control_files=("/u01/app/oracle/oradata/ssh/control01.ctl", "/u01/app/oracle/oradata/ssh/control02.ctl", "/u01/app/oracle/oradata/ssh/control03.ctl"
db_recovery_file_dest=/u01/app/oracle/flash_recovery_area
db_recovery_file_dest_size=2147483648
###########################################
# Job Queues
###########################################
job_queue_processes=10
###########################################
# Miscellaneous
###########################################
compatible=10.2.0.1.0
###########################################
# Processes and Sessions
###########################################
processes=150
###########################################
# SGA Memory
###########################################
sga_target=448790528
###########################################
# Security and Auditing
###########################################
audit_file_dest=/u01/app/oracle/admin/ssh/adump
remote_login_passwordfile=EXCLUSIVE
###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=sshXDB)"
###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=148897792
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1
注意不能直接修改spfile文件 不能直接使用文本编辑器vi编辑它,只能通过alter system修改。
在数据库运行的时候,可以修改spfile中的参数。
sqlplus / as sysdba
--这句话的作用是将初始化参数文件创建spfile文件
create spfile='/u01/app/oracle/product/10.2.0/db_1/dbs/spfilessh.ora' from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initssh.ora2';
下边是spfile文件的内容:
ssh.__java_pool_size=4194304
ssh.__large_pool_size=4194304
ssh.__shared_pool_size=121634816
ssh.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/ssh/adump'
*.background_dump_dest='/u01/app/oracle/admin/ssh/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/oradata/ssh/control01.ctl','/u01/app/oracle/oradata/ssh/control02.ctl','/u01/app/oracle/oradata/ssh/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/ssh/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='ssh'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=sshXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=148897792
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=448790528
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/ssh/udump'
如果initssh.ora2这个初始化参数文件有问题,那么spfile文件需要重新创建。
在sqlplus下执行
startup nomount启动实例。
5.
创建Initsshl.ora2里边所涉及的所有目录
用root账户创建文件夹然后给oracle11g用户授予权限
[oracle11g@localhost dbs]$ mkdir -p /u01/app/oracle/admin/ssh/bdump
[oracle11g@localhost dbs]$ mkdir -p /u01/app/oracle/admin/ssh/cdump
[oracle11g@localhost dbs]$ mkdir -p /u01/app/oracle/admin/ssh/udump
[oracle11g@localhost dbs]$ mkdir -p /u01/app/oracle/admin/ssh/adump
[oracle11g@localhost dbs]$ su - root
口令:
[root@localhost ~]# chown -R oracle11g:dba /u01/app/oracle/admin/ssh/udump
[root@localhost ~]# chown -R oracle11g:dba /u01/app/oracle/admin/ssh/adump
[root@localhost ~]# chown -R oracle11g:dba /u01/app/oracle/admin/ssh/cdump
[root@localhost ~]# chown -R oracle11g:dba /u01/app/oracle/admin/ssh/bdump
6.授予好权限后,执行sqlplus / as sysdba命令
执行startup nomount
然后执行create database ssh....
下边是脚本:
有两种执行方式:
一种是将下边的语句一个字母不差的敲出来执行。
另一种是将脚本保存为一个文件,例如:cd.sql将这个文件保存在linux文件里边。
然后执行 @/1/cd.sql就可以运行这个脚本。
CREATE DATABASE ssh
USER SYS IDENTIFIED BY ghru333
USER SYSTEM IDENTIFIED BY ghru333
LOGFILE
GROUP 1 ('/u01/app/oracle/oradata/ssh/redo01_1','/u01/app/oracle/oradata/ssh/redo01_2')
SIZE 100M,
GROUP 2 ('/u01/app/oracle/oradata/ssh/redo02_1','/u01/app/oracle/oradata/ssh/redo02_2')
SIZE 100M,
GROUP 3 ('/u01/app/oracle/oradata/ssh/redo03_1','/u01/app/oracle/oradata/ssh/redo03_2')
SIZE 100M
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
MAXINSTANCES 1
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
ARCHIVELOG
DATAFILE '/u01/app/oracle/oradata/ssh/system01.dbf' SIZE 325M REUSE
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/u01/app/oracle/oradata/ssh/sysaux01.dbf' SIZE 325M REUSE
DEFAULT TABLESPACE tbs_1 DATAFILE '/u01/app/oracle/oradata/ssh/tbs1.dbf' SIZE 1225M
REUSE
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/u01/app/oracle/oradata/ssh/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs1
DATAFILE '/u01/app/oracle/oradata/ssh/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
SQL> @/1/cd.sql
CREATE DATABASE ssh
*
ERROR at line 1:
ORA-01501: CREATE DATABASE failed
ORA-00200: control file could not be created
ORA-00202: control file: '/u01/app/oracle/oradata/ssh/control02.ctl'
ORA-27038: created file already exists
Additional information: 1
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 448790528 bytes
Fixed Size 1219928 bytes
Variable Size 130024104 bytes
Database Buffers 314572800 bytes
Redo Buffers 2973696 bytes
SQL> @/1/cd.sql
Database created.
Create database 不会一次就执行成功。多执行几次。
如果出现问题,要知道哪里出了问题。
观察日志文件。
我记得是最后要执行那个root.sh 和catalog.sh好像是,但是catalog.sh不知道为什么执行不了,欢迎大家来补充。