Linux环境安装Oracle数据库

执念博客
2020-12-17 / 0 评论 / 121 阅读 / 耗时: 29 ms / 正在检测是否收录...
温馨提示:
本文最后更新于2021年05月05日,已超过1315天没有更新,若内容或图片失效,请留言反馈。
广告

点击广告查看隐藏内容....

1.创建目录
mkdir -p /software/oracle
mkdir -p /data/oradata
chmod -R 777 /data/oradata

2.上传文件
oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm
oracle-database-ee-18c-1.0-1.x86_64.rpm
文件下载地址:
链接: https://pan.baidu.com/s/12oXOZUtSAgkohGjhCHlkYA 提取码: np9a

3.数据库安装
yum -y localinstall /software/oracle/oracle-database-preinstall-18c-1.0-1.el7.x86_64.rpm
yum -y localinstall /software/oracle/oracle-database-ee-18c-1.0-1.x86_64.rpm

4.配置数据库实例

vi /etc/init.d/oracledb_ORCLCDB-18c

修改其为sid
export ORACLE_SID=ORCL
export CHARSET=UTF8
export PDB_NAME=zhinianblog

修改配置文件(该文件可能会复制遗漏,注意查看)
vi /etc/sysconfig/oracledb_ORCL-18c.conf

#This is a configuration file to setup the Oracle Database.
#It is used when running '/etc/init.d/oracledb_ORCLCDB configure'.
#Please use this file to modify the default listener port and the
#Oracle data location.
# LISTENER_PORT: Database listener
LISTENER_PORT=1521
# ORACLE_DATA_LOCATION: Database oradata location
ORACLE_DATA_LOCATION=/data/oradata
# EM_EXPRESS_PORT: Oracle EM Express listener
EM_EXPRESS_PORT=5500

5.创建数据库
/etc/init.d/oracledb_ORCLCDB-18c configure

5.1 设置监听等
查找该文件(admin/tnsnames.ora):
find / -name "*tnsnames.ora*"

添加如下内容:

LISTENER_ZHINIANBLOG =】
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

ZHINIANBLOG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ZHINIANBLOG)
)
)

6.登陆
sqlplus / as sysdba

7.sqlplus命令无法使用

①找到ORACLE_HOME的位置,我的是:/u01/app/oracle/product/11.2.0/dbhome_1(该路径在/etc/init.d/oracledb_ORCLCDB-18c 文件中) /opt/oracle/product/18c/dbhome_1
②切换到oracle用户(是什么用户安装oracle的就用什么用户)命令:su oracle
③vi .bash_profile(切换到根目录:”cd ~” 执行这条命令)
④在最后增加配置文件
export ORACLE_HOME=/opt/oracle/product/18c/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG="AMERICAN_AMERICA.UTF8"
export ORACLE_SID=ORCL
export PDB_NAME=zhinianblog
⑤启用该资源文件,命令:source .bash_profile

8.启动数据库
sql> startup;

9.关闭数据库
sql> shutdown immediate;

10.查询所有用户
select username from all_users;

11.修改用户密码
alter user zhinianblog identified by 123456;

12.解锁用户
alter user zhinianblog account unlock;

13.创建用户
alter session set container=zhinianblog;
startup;
create user zhinianblog identified by zhinianblog;
grant create session,create table,unlimited tablespace to zhinianblog;
grant create sequence,select any sequence to zhinianblog;
alter user zhinianblog account unlock;

13.1.删除用户
drop user zhinianblog cascade;

--删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
--删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
--删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles;
--删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;

14.尝试使用DbVisualizer连接数据库
①ping Server不通,尝试开启防火墙
②ping Server不通,尝试开启数据库监听
(1) 进入监听器控制台,命令:lsnrctl
(2) 启动监听器,命令:start
(3) 退出监听器控制台,命令:exit
③ORA-28040: 没有匹配的验证协议
(1)查找admin/sqlnet.ora文件,末尾添加SQLNET.ALLOWED_LOGON_VERSION=8
find / -name "*sqlnet.ora*"
④sqlplus可以登录DIP用户,DbVisualizer无法登陆
alter user zhinianblog identified by 123456 container=all;
⑤如果使用sqlplus可以登录,但是DbVisualizer无法登陆,修改密码为纯数字后尝试;

15.设置数据库开机自启
第一步:
vi /etc/oratab
找到“orcl:/u01/app/oracle/product/12.1.0/dbhome_1:N”,改为“orcl:/u01/app/oracle/product/12.1.0/dbhome_1:Y”

第二步:
新建sh脚本
mkdir -p /data/shell/
vi startOracle.sh

su oracle -lc "/opt/oracle/product/18c/dbhome_1/bin/lsnrctl start"
su oracle -lc "/opt/oracle/product/18c/dbhome_1/bin/dbstart"

chmod -R 757 /data/shell/

第三步:
设置pdb数据库自启
sqlplus / as sysdba

执行以下触发器:
CREATE TRIGGER open_all_pdbs
AFTER STARTUP
ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'alter pluggable database all open';
END open_all_pdbs;
/

第四步:
设置sh脚本自启

查找该文件
find / -name "*rc.local*"

vi /etc/rc.local
sh /data/shell/startOracle.sh

vi /etc/rc.d/rc.local
sh /data/shell/startOracle.sh

设置执行权限
chmod +x /data/shell/startOracle.sh
chmod +x /etc/rc.d/rc.local

16.创建表空间
create tablespace zhinian datafile '/data/database/zhinian.dbf' size 500m;
alter user zhinianblog default tablespace zhinian;

17.异常场景

17.1.启动数据库报
LRM-00109: could not open parameter file '/opt/oracle/product/18c/dbhome_1/dbs/initzhinianblog.ora'

cp /opt/oracle/admin/ORCL/pfile/init.ora.8232020213539 /opt/oracle/product/18c/dbhome_1/dbs/
修改文件名即可

17.2.启动数据库报 ORA-00845: MEMORY_TARGET not supported on this system
重启服务器即可

本文共 444 个字数,平均阅读时长 ≈ 2分钟

点击广告查看隐藏内容....

3

打赏

海报

正在生成.....

评论 (0)

语录
取消