安装好数据库后,
启动数据库必须以oracle用户身份进行。
可以通过SQLPlus管理器来启动数据库。以Sysdba身份登录,可以启动,命令如下:
sqlplus "/as sysdba"
进入之后,startup 即可启动。
但是想要外面连接到这个数据库,必须还要启动它的监听器:
lsnrctl start
之后显示监听器已经监听 "law" 这个数据库实例了。
现在Linux下制作一个命令来启动比较方便
Oracle自带的
启动脚本在$ORACLE_HOME/bin/dbstart
修改其中监听器位置:
# Set this to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=$ORACLE_HOME
关闭脚本在$ORACLE_HOME/bin/dbshut
加上关闭监听器的脚本:
Done之前加上:
lsnrctl stop
可以自己建立启动脚本文件dbstart.sh,内容如下:
#!/bin/bash
echo "Starting oracle10"
su - oracle -c "/database/app/10.2.0/bin/dbstart"
#su - oracle -c "/u01/product/10.2.0/db_1/bin/emctl start dbconsole"
echo "Done"
关闭脚本文件:dbshut.sh,内容如下:
#!/bin/bash
echo "Shut down oracle10"
su - oracle -c "/database/app/10.2.0/bin/dbshut"
#su - oracle -c "/u01/product/10.2.0/db_1/bin/emctl start dbconsole"
echo "Done"
这样,己是在root用户下,也可以用这2个命令来启动和关闭数据库。
参考资料:
http://www.linuxdiyf.com/viewarticle.php?id=78096
但是关于如何设置为服务启动。按照上面设置无效。
关于如何设置为服务启动,请参考如下方案:
在目录下建立文件:/etc/rc.d/init.d/oracle10g
内容为:
#!/bin/bash
#
# chkconfig: 35 95 1
# description: init script to start/stop oracle database 10g, TNS listener, EMS, isqlplus
#
#
#
# match these values to your environment:
export ORACLE_BASE=/home/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.1.0/db_1
# export ORACLE_TERM=xterm
export PATH=$PATH:$ORACLE_HOME/bin
export NLS_LANG='american_america.ZHS16GBK'
export ORACLE_SID=esales
# export DISPLAY=localhost:0
export ORACLE_USER=oracle
# see how we are called:
case $1 in
start)
su - "$ORACLE_USER"<<EOO
lsnrctl start
sqlplus /nolog<<EOS
connect / as sysdba
startup
EOS
emctl start dbconsole
isqlplusctl start
EOO
;;
stop)
su - "$ORACLE_USER"<<EOO
lsnrctl stop
sqlplus /nolog<<EOS
connect / as sysdba
shutdown immediate
EOS
emctl stop dbconsole
isqlplusctl stop
EOO
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac
二、 以root用户执行以下命令
chmod 755 /etc/rc.d/init.d/oracle10g
chkconfig --add oracle10g
三、 重启服务
service oracle10g stop
service oracle10g start