您的位置:首页 > 数据库 > Oracle

oracle 手动创建数据库

2016-12-08 00:00 302 查看
1 创建存放数据库文件的路径,并修改权限

[root@wangzilong oradata]# mkdir -p /u01/product/oradata/start1
[root@wangzilong oradata]# chown oracle.dba start1

2 admin 下实例名称下创建adump,dpdump 审计文件夹
[root@wangzilong admin]# chown -R oracle.dba start1/
[root@wangzilong admin]# ll
total 12
drwxr-x--- 5 oracle dba 4096 Nov 18 16:41 orcl
drwxr-xr-x 4 oracle dba 4096 Dec  8 11:52 sidwzl
drwxr-xr-x 4 oracle dba 4096 Dec  8 13:54 start1  # 权限设置为oracle.dba
[root@wangzilong start1]# ll
total 8
drwxr-xr-x 2 oracle dba 4096 Dec  8 13:54 adump
drwxr-xr-x 2 oracle dba 4096 Dec  8 13:54 dpdump

3 创建参数文件

参数文件默认是放在 /u01/product/11g/dbs 下面,但是我们手动创建的时候也可以放在其他地方,只是在startup 启动的时候就要指定路径,为了方便,我们还是放在/u01/product/11g/dbs 下面。命名规则initORACLE_SID.ora

[root@wangzilong dbs]# touch initstart1.ora
[root@wangzilong dbs]# ll initstart1.ora
-rw-r--r-- 1 root root 0 Dec  8 13:58 initstart1.ora
[root@wangzilong dbs]# chown oracle.dba initstart1.ora
[root@wangzilong dbs]# ll initstart1.ora
-rw-r--r-- 1 oracle dba 0 Dec  8 13:58 initstart1.ora
# 参数文件内容如下:
db_block_size=8192
db_name =start1
control_files='/u01/product/oradata/start1/control01.ctl'
db_recovery_file_dest='/u01/product/fast_recovery_area'
db_recovery_file_dest_size=4g
undo_tablespace=undotbs2

4 创建密码文件

在oracle 用户下运行:

bash-4.1$ orapwd file='/u01/product/oradata/pwd/start1pwd.pwd' password=oracle

[root@wangzilong pwd]# ll
total 8
-rw-r----- 1 oracle dba 1536 Dec  8 12:35 sidwzlpwd.pwd
-rw-r----- 1 oracle dba 1536 Dec  8 14:12 start1pwd.pwd

注意:密码文件生成的时候先运行环境变量. .db 且file=‘’ 之间没有空格

5 关闭数据库并启动到nomount状态下

export oracle_sid=start1 先设置实例名称在登录sqlplus 启动到nomount 下

bash-4.1$ . .db
bash-4.1$ export ORACLE_SID=start1
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Dec 8 14:22:32 2016

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

Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.

Total System Global Area  250560512 bytes
Fixed Size		    2227256 bytes
Variable Size		  192938952 bytes
Database Buffers	   50331648 bytes
Redo Buffers		    5062656 bytes
# 启动到nomount 成功
SQL> startup nomount force
ORACLE instance started.

Total System Global Area  250560512 bytes
Fixed Size		    2227256 bytes
Variable Size		  192938952 bytes
Database Buffers	   50331648 bytes
Redo Buffers		    5062656 bytes
SQL> @ /tmp/createdb02.sql

Database created.
@ 创建数据库成功

创建数据库的语法:

create database start1
character set al32utf8
logfile
group 1 '/u01/product/oradata/start1/redo01.log' size 50M,
group 2 '/u01/product/oradata/start1/redo02.log' size 50M,
group 3 '/u01/product/oradata/start1/redo03.log' size 50M
datafile '/u01/product/oradata/start1/system01.dbf' size 50M autoextend on
sysaux datafile '/u01/product/oradata/start1/sysaux01.dbf' size 50M autoextend on
undo tablespace undotbs2 datafile '/u01/product/oradata/start1/undotbs01.dbf' size 100M autoextend on
default temporary tablespace temp2 tempfile '/u01/product/oradata/start1/temp01.dbf' size 50M
default tablespace space1 datafile '/u01/product/oradata/space01.dbf' size 100M autoextend on ;
# undotbs2 要和参数文件中的undo 表空间的名字一致,否则创建失败

如果需要有字典,需要执行脚本:$ORACLE_HOME/rdbms/admin/catalog.sql 和 catproc.sql

6 手动删除实例

6.1 查看控制文件,日志文件,数据文件的物理地址

SQL> select status,name from v$controlfile;

STATUS	   NAME
---------- --------------------------------------------------
/u01/oracle/oradata/wzl/control01.ctl
SQL> select group#,member from v$logfile;

GROUP# MEMBER
---------- --------------------------------------------------
1 /u01/oracle/oradata/wzl/redo01.log
2 /u01/oracle/oradata/wzl/redo02.log
3 /u01/oracle/oradata/wzl/redo03.log
FILE# NAME
---------- --------------------------------------------------
1 /u01/oracle/oradata/wzl/system01.dbf
2 /u01/oracle/oradata/wzl/sysaux01.dbf
3 /u01/oracle/oradata/wzl/undo01.dbf
4 /u01/oracle/oradata/wzl/space01.dbf

6.2 关闭数据库

SQL> shutdown abort
ORACLE instance shut down.

6.3 使用exclusive restart 把数据库重新启动到mount状态下

SQL> startup mount exclusive restrict;
ORACLE instance started.

Total System Global Area  238034944 bytes
Fixed Size		    2227136 bytes
Variable Size		  180356160 bytes
Database Buffers	   50331648 bytes
Redo Buffers		    5120000 bytes
Database mounted.

6.4 修改参数为允许受限的会话模式

SQL> alter system enable restricted session;

System altered.

6.5 删除数据库

SQL> drop database;

Database dropped.

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

6.6 删除数据文件,日志文件,控制文件

[oracle@dghost tmp]$ rm -rf $ORACLE_BASE/admin/$ORACLE_SID
[oracle@dghost tmp]$ rm -rf $ORACLE_BASE/oradata/$ORACLE_SID
[oracle@dghost fast_recovery_area]$ rm -rf $ORACLE_BASE/fast_recovery_area/$ORACLE_SID
[oracle@dghost fast_recovery_area]$ rm -rf $ORACLE_HOME/dbs/*$ORACLE_SID*

6.7 最后删除之前配置的环境
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  建库 删库