欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Create database 创建数据库

程序员文章站 2022-05-09 08:42:47
首先在ORACLE用户下进入.bash_profile文件 [oracle@linux02 ~]$ vi .bash_profile export ORACLE_SID=hldbexport ORACLE_UNQNAME=hldb 将ORACLE_SID和ORACLE_UNQNAME修改为新的数据库 ......

首先在ORACLE用户下进入.bash_profile文件

[oracle@linux02 ~]$ vi .bash_profile
export ORACLE_SID=hldb
export ORACLE_UNQNAME=hldb

将ORACLE_SID和ORACLE_UNQNAME修改为新的数据库名字

[oracle@linux02 ~]$ source .bash_profile

刷新文件

 

----------------------------------------------------------------------------------------------------------

进入/u01/app/oracle/oradata目录下

[oracle@linux02 oradata]$ cd /u01/app/oracle/oradata
[oracle@linux02 oradata]$ pwd
/u01/app/oracle/oradata

新建一个文件夹
[oracle@linux02 oradata]$ mkdir hldb

进入$ORACLE_HOME/dbs

[oracle@linux02 ~]$ cd $ORACLE_HOME/dbs

创建密码文件
[oracle@linux02 dbs]$ orapwd file=orapwhldb password=oracle

建立一个新的参数文件并写入相关信息

 

[oracle@linux02 dbs]$ vi inithldb.ora
DB_NAME='hldb'
CONTROL_FILES='/u01/app/oracle/oradata/hldb/control01.ctl'
MEMORY_TARGET=900M

---------------------------------------------------------------------------

以SYS身份启动sqlplus

[oracle@linux02 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Apr 23 10:03:27 2018

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

Connected to an idle instance.

创建spfile文件

SQL> create spfile from pfile;

File created.

启动实例,不加载数据库

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 939495424 bytes
Fixed Size 2233960 bytes
Variable Size 545261976 bytes
Database Buffers 385875968 bytes
Redo Buffers 6123520 bytes

将以下参数复制进去
CREATE DATABASE hldb
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('/u01/app/oracle/oradata/hldb/redo01.log') SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/u01/app/oracle/oradata/hldb/redo02.log') SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/u01/app/oracle/oradata/hldb/redo03.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/hldb/system01.dbf' SIZE 325M REUSE
SYSAUX DATAFILE '/u01/app/oracle/oradata/hldb/sysaux01.dbf' SIZE 325M REUSE
DEFAULT TABLESPACE users
DATAFILE '/u01/app/oracle/oradata/hldb/users01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/u01/app/oracle/oradata/hldb/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs
DATAFILE '/u01/app/oracle/oradata/hldb/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

-------------------------------------------------------------------------------------------------

数据库文件逐一创建
SQL> CREATE DATABASE hldb
2 USER SYS IDENTIFIED BY oracle
3 USER SYSTEM IDENTIFIED BY oracle
4 LOGFILE GROUP 1 ('/u01/app/oracle/oradata/hldb/redo01.log') SIZE 100M BLOCKSIZE 512,
5 GROUP 2 ('/u01/app/oracle/oradata/hldb/redo02.log') SIZE 100M BLOCKSIZE 512,
6 GROUP 3 ('/u01/app/oracle/oradata/hldb/redo03.log') SIZE 100M BLOCKSIZE 512
7 MAXLOGFILES 5
8 MAXLOGMEMBERS 5
9 MAXLOGHISTORY 1
10 MAXDATAFILES 100
11 CHARACTER SET AL32UTF8
12 NATIONAL CHARACTER SET AL16UTF16
13 EXTENT MANAGEMENT LOCAL
14 DATAFILE '/u01/app/oracle/oradata/hldb/system01.dbf' SIZE 325M REUSE
15 SYSAUX DATAFILE '/u01/app/oracle/oradata/hldb/sysaux01.dbf' SIZE 325M REUSE
16 DEFAULT TABLESPACE users
17 DATAFILE '/u01/app/oracle/oradata/hldb/users01.dbf'
18 SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
19 DEFAULT TEMPORARY TABLESPACE tempts1
20 TEMPFILE '/u01/app/oracle/oradata/hldb/temp01.dbf'
21 SIZE 20M REUSE
22 UNDO TABLESPACE undotbs
23 DATAFILE '/u01/app/oracle/oradata/hldb/undotbs01.dbf'
24 SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

Database created.
-------------------------------------------------------------------------------------------------
In SQL*Plus, connect to your Oracle Database instance with the SYSDBA administrative privilege:
[oracle@linux02 ~]$ sqlplus / as sysdba

分别执行以下命令

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
@?/rdbms/admin/utlrp.sql


In SQL*Plus, connect to your Oracle Database instance as SYSTEM user:
[oracle@linux02 ~]$ sqlplus system/oracle

@?/sqlplus/admin/pupbld.sql

-------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------
export ORACLE_SID=VDEDU 在本会话框里切成VDEDU这个数据库


select instance_name from v$instance;查询当前数据库实例的名字


shutdown immediate;关闭数据库