一、创建用户及表空间
1.连接数据库
[root@localhost ~]# su - oracle
[oracle@localhost ~]$ sqlplus /nolog #进入sqlplus环境
[oracle@localhost ~]$ conn / as sysdba
2.创建表空间
#指定表空间存放位置,磁盘限额
SQL> create tablespace test datafile '/main/oracle/oradata/test.dbf' size 1024M autoextend on next 1024M maxsize 10240M extent management local;
#删除表空间
drop tablespace hjb including contents and datafiles;
3.创建oracle用户
#密码设置为test,指定默认管理test表空间
SQL> create user test identified by test default tablespace test;
4.授权用户权限
SQL> grant connect, resource to test;
#connect权限:可以连接数据库、创建表和视图等数据库对象
#resource权限:可以创建表、视图等数据库对象
5.不对用户做表空间限额控制
SQL> grant unlimited tablespace to test;
二、修改Oracle数据库编码
SQL> select userenv('language') from dual; #先查看数据库的字符集 SQL> shutdown immediate; SQL> startup mount; SQL> alter system enable restricted session; SQL> alter system set job_queue_processes=0; SQL> alter database open; SQL> alter database character set internal_use UTF8; SQL> shutdown immediate; SQL> startup SQL> alter system disable restricted session;
补充:startup启动数据库过程 nomount --> mount --> open
三、配置开机启动脚本
修改允许dbstart/dbshut来启动和关闭oracle数据库实例
[oracle@localhost ~]$ vi /etc/oratab :orcl:/main/oracle/11.2:Y
2. 默认dbstart调用的tnslnr脚本位置有错,需要我们修改下,要不然dbstart启动会报错,找到这一行修改为ORACLE安装目录
[oracle@localhost ~]$ vi $ORACLE_HOME/bin/dbstart
ORACLE_HOME_LISTENER=/ade/vikrkuma_new/oracle” --〉 “ORACLE_HOME_LISTENER=$ORACLE_HOME”
3.编写SysV脚本
#!/bin/bash #chkconfig:345 66 46 #description:startup script for oracle databases export ORACLE_BASE=/main/oracle/ export ORACLE_HOME=/main/oracle/11.2 export PATH=$PATH:$ORACLE_HOME/bin export ORACLE_SID=orcl ORA_OWNR="oracle" case "$1" in start) echo -n "Starting Oracle:" su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start" su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart" su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole" echo "Starting Oracle Success: OK" ;; stop) echo -n "Shutdown Oracle:" su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole" su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut" su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop" echo "Shutdown Oracle Success: OK" ;; restart) $0 stop $0 start ;; *) echo "Usage: basename $0 start|stop|restart" exit 1 esac exit 0
[oracle@localhost ~]$ chkconfig --add oracle11
[oracle@localhost ~]$ chkconfig oracle11 on
#启动Oracle顺序
lsnrctl start(启动Oracle) --> 登陆数据库执行startup(启动数据库实例) --> emctl start dbconsole(启动OEM)
#关闭Oracle顺序
emctl stop dbconsole(OEM管理1158) --> lsnrctl stop(关闭Oracle监听1521)--> 登陆数据库执行shutdown immediate;(关闭数据库实例)