centos8安装部署Oracle Database Free

前言

centos8安装部署Oracle Database Free

安装部署

服务器安装
  1. 下载centos8镜像(选择镜像:CentOS-Stream-8-20230523.0-x86_64-dvd1.iso)并安装系统,具体细节不再赘述
  2. 关闭centos8服务器的防火墙与selinux,并配置ip
部署oracle
  • 注:先下载文件Oracle Linux==>oracle-database-free-23c-1.0-1.el8.x86_64.rpm并放置到服务器的家目录下
[root@localhost ~]# cd ~
[root@localhost ~]# sudo -s
[root@localhost ~]# curl -L -o oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm https://yum.oracle.com/repo/OracleLinux/OL8/developer/x86_64/getPackage/oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
[root@localhost ~]# dnf -y localinstall oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
[root@localhost ~]# dnf -y localinstall oracle-database-free*
[root@localhost ~]# /etc/init.d/oracle-free-23c configure
Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN 
accounts:   	# 输入密码
Confirm the password:   # 再次输入密码

Configuring Oracle Listener.
Listener configuration succeeded.
Configuring Oracle Database FREE.
Enter SYS user password: 
*********
Enter SYSTEM user password: 
********
Enter PDBADMIN User Password: 
********
Prepare for db operation
7% complete
Copying database files
29% complete
Creating and starting Oracle instance
30% complete
33% complete
36% complete
39% complete
43% complete
Completing Database Creation
47% complete
49% complete
50% complete
Creating Pluggable Databases
54% complete
71% complete
Executing Post Configuration Actions
93% complete
Running Custom Scripts
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/FREE.
Database Information:
Global Database Name:FREE
System Identifier(SID):FREE
Look at the log file "/opt/oracle/cfgtoollogs/dbca/FREE/FREE.log" for further details.

Connect to Oracle Database using one of the connect strings:
     Pluggable database: localhost.localdomain/FREEPDB1
     Multitenant container database: localhost.localdomain
设置 Oracle 数据库自由环境变量
[root@localhost /]#export ORACLE_SID=FREE 
[root@localhost /]#export ORAENV_ASK=NO 
[root@localhost /]#. /opt/oracle/product/23c/dbhomeFree/bin/oraenv
The Oracle base has been set to /opt/oracle     

连接oracle数据库

使用操作系统身份验证在本地连接
[root@localhost /]# cd /opt/oracle/product/23c/dbhomeFree/bin/
[root@localhost bin]# ./sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sat Jun 3 12:13:57 2023
Version 23.2.0.0.0

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

ERROR:
ORA-01017: invalid credential or not authorized; logon denied


Enter user-name: SYSTEM	# 输入账户
Enter password: 		# 输入密码
Last Successful login time: Sat Jun 03 2023 11:45:39 +08:00

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0
  • 注:类似于以上内容的输出确认您现在已连接到数据库
使用账户登录本地数据库
[root@localhost bin]# export ORACLE_SID=FREE
[root@localhost bin]# export ORAENV_ASK=NO 
[root@localhost bin]# . /opt/oracle/product/23c/dbhomeFree/bin/oraenv
The Oracle base has been set to /opt/oracle
[root@localhost /]# cd /opt/oracle/product/23c/dbhomeFree/bin/
[root@localhost bin]# ./sqlplus [email protected]:1521/FREE as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sat Jun 3 21:52:25 2023
Version 23.2.0.0.0

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

Enter password: 	# 输入密码

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL> 

Oracle创建表空间、创建用户以及授权

[root@localhost bin]# ./sqlplus [email protected]:1521/FREE as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sat Jun 3 21:52:25 2023
Version 23.2.0.0.0

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

Enter password: 	# 输入密码

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

# 创建临时表空间
SQL> create temporary tablespace devopstmp tempfile 'devopstmp.dbf' size 500M autoextend on next 5M maxsize unlimited extent management local;

# 创建表空间
SQL> create tablespace devops datafile 'devops.dbf' size 500M autoextend on next 5M maxsize unlimited;

Tablespace created.

SQL> alter session set "_ORACLE_SCRIPT"=TRUE;

Session altered.

## 创建c##demoa用户,并设置表空间为devops,临时表空间为devopstmp
SQL> create user c##demoa identified by Data2023 default tablespace devops temporary tablespace devopstmp;

User created.

# 给用户授权
SQL> grant connect,resource,dba to c##demoa;

Grant succeeded.

# 用c##demoa账户登录,并创建表,新增数据,查询数据(新开终端执行如下命令)
[root@localhost /]# export ORACLE_SID=FREE
[root@localhost /]# export ORAENV_ASK=NO 
[root@localhost /]# . /opt/oracle/product/23c/dbhomeFree/bin/oraenv
The Oracle base has been set to /opt/oracle
[root@localhost /]# cd /opt/oracle/product/23c/dbhomeFree/bin/
[root@localhost bin]# ./sqlplus c##[email protected]:1521/FREE

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sun Jun 4 01:21:36 2023
Version 23.2.0.0.0

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

Enter password: 

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL> create table t1(id varchar2(50) primary key, name char(200) not null);

Table created.

SQL> insert into t1 values ('11', '张三');

1 row created.

SQL> select * from t1;

ID
--------------------------------------------------
NAME
--------------------------------------------------------------------------------
11
张三

# 创建c##demob用户,并设置表空间为devops,临时表空间为devopstmp(使用第一个终端)
SQL> create user c##demob identified by Data2023 default tablespace devops temporary tablespace devopstmp;

User created.

# 给用户授权
SQL> grant connect,resource,dba to c##demob;

Grant succeeded.

# 用c##demoa账户登录,查询用户c##demoa的表数据,并创建表,新增数据,查询数据(新开终端执行如下命令)
[root@localhost /]# export ORACLE_SID=FREE
[root@localhost /]# export ORAENV_ASK=NO 
[root@localhost /]# . /opt/oracle/product/23c/dbhomeFree/bin/oraenv
The Oracle base has been set to /opt/oracle
[root@localhost /]# cd /opt/oracle/product/23c/dbhomeFree/bin/
[root@localhost bin]# ./sqlplus c##[email protected]:1521/FREE

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sun Jun 4 01:21:36 2023
Version 23.2.0.0.0

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

Enter password: 

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL> select * from t1;
select * from t1
              *
ERROR at line 1:
ORA-00942: table or view does not exist
- 注:输出结果表面:同一个表空间下此用户看不到其它用户的表数据

SQL> select * from c##demoa.t1;
select * from t1
              *
ERROR at line 1:
ORA-00942: table or view does not exist
- 注:输出结果表面:同一个表空间下此用户看不到其它用户的表数据,需要授权相应权限;

# 到c##demoa用户下的sql终端执行如下一条命令
SQL> grant select on c##demoa.t1 to c##demob;

Grant succeeded.

# 到c##demob用户下的sql终端执行如下一条命令
SQL> select * from c##demoa.t1;

ID
--------------------------------------------------
NAME
--------------------------------------------------------------------------------
11
李四
- 注:输出结果表面:授权情况下,同一个表空间下此用户可以看到其它用户的表数据;

#SQL> select * from all_tables where TABLESPACE_NAME = 'devops'

SQL> create table t1(id varchar2(50) primary key, name char(200) not null);

Table created.

SQL> insert into t1 values ('11', '李四');

1 row created.

SQL> select * from t1;

ID
--------------------------------------------------
NAME
--------------------------------------------------------------------------------
11
李四
  • 总结:Oracle 不同用户,即使共用一个表空间,数据也是互不影响,相互独立
将一个用户下的表结构和数据复制到另一个用户下
[root@localhost /]# export ORACLE_SID=FREE
[root@localhost /]# export ORAENV_ASK=NO 
[root@localhost /]# . /opt/oracle/product/23c/dbhomeFree/bin/oraenv
The Oracle base has been set to /opt/oracle
[root@localhost /]# cd /opt/oracle/product/23c/dbhomeFree/bin/
[root@localhost bin]# ./sqlplus [email protected]:1521/FREE as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sat Jun 3 21:52:25 2023
Version 23.2.0.0.0

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

Enter password: 	# 输入密码

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

# 在数据库服务器上创建目录:mkdir /root/dump_dir
SQL> create directory dump_dir as '/root/dump_dir';

Directory created.

SQL> grant read,write on directory dump_dir to C##DEMOA;

Grant succeeded.

SQL> quit;
[root@localhost bin]# expdp C##DEMOA/Data2023 directory=dump_dir dumpfile=DEMOA.dmp
[root@localhost bin]# impdp C##DEMOB/Data2023 directory=dump_dir dumpfile=DEMOA.dmp REMAP_SCHEMA=DEMOA:DEMOB EXCLUDE=USER

oracle服务设置开机自启动

[root@localhost /]# systemctl daemon-reload
[root@localhost /]# systemctl enable oracle-free-23c
oracle-free-23c.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable oracle-free-23c
[root@localhost /]# systemctl start oracle-free-23c
[root@localhost /]# systemctl status oracle-free-23c
● oracle-free-23c.service - SYSV: This script is responsible for taking care of configuring the RPM Oracle FREE Database and its associated services.
   Loaded: loaded (/etc/rc.d/init.d/oracle-free-23c; generated)
   Active: active (exited) since Sat 2023-06-03 12:28:09 CST; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8178 ExecStart=/etc/rc.d/init.d/oracle-free-23c start (code=exited, status=0/SUCCESS)

Jun 03 12:28:09 localhost.localdomain systemd[1]: Starting SYSV: This script is responsible for taking care of configuring the RPM Oracle FREE Database and its associated services....
Jun 03 12:28:09 localhost.localdomain oracle-free-23c[8178]: The Oracle Database instance FREE is already started.
Jun 03 12:28:09 localhost.localdomain systemd[1]: Started SYSV: This script is responsible for taking care of configuring the RPM Oracle FREE Database and its associated services..

结语

Oracle Database 23c 免费版——开发者版
Oracle Database Free Download
Python python-oracledb Driver
适用于 Oracle Linux x86-64 的 Docker 容器的 Oracle 数据库企业版安装指南

你可能感兴趣的:(mysql,数据库,oracle,服务器)