参考链接: (Oracle Database 11g 快捷版 第 2 版)[https://www.oracle.com/cn/database/technologies/oracle-database-express-edition-11g-release2.html] (Oracle Database 11g 快捷版 第 2 版 下载)[https://www.oracle.com/cn/database/technologies/express-edition.html] (Database Express Edition Installation Guide)[https://docs.oracle.com/cd/E17781_01/install.112/e18802/toc.htm]

1 安装要求

看看就行,现在(2021)基本都满足的。

1.1 系统要求

Requirement Value
运行内存(RAM) 最小256MB,建议512MB
硬盘空间 最小1.5GB
依赖包 glibc 大于等于 2.3-2.41
make 大于等于 3.80
binutils 大于等于 2.16.91.0.5
gcc 大于等于 4.1.2
libaio 大于等于 0.3.104

1.2 交换空间(Swap Space)要求

Oracle Database XE所需的最小交换空间为2GB或磁盘空间的两倍RAM,以较小的为准。

1.3 安装权限要求

安装Oracle数据库XE需要具有root权限。

2 安装与配置

2.1 下载Oracle 11g XE

(Oracle Database 11g 快捷版 第 2 版 下载)[https://www.oracle.com/cn/database/technologies/express-edition.html]

2.2 安装配置

Oracle 11g XE 安装文件oracle-xe-11.2.0-1.0.x86_64.rpm.zip上传过程省略。上传完成后如下所示:

  1. [root@localhost opt]# ll
  2. total 308488
  3. drwxrwxr-x. 4 root root 76 Aug 29 2011 Disk1
  4. -rw-r--r--. 1 root root 315891481 Jul 19 21:50 oracle-xe-11.2.0-1.0.x86_64.rpm.zip
  5. [root@localhost opt]# pwd
  6. /opt
  7. [root@localhost opt]#

使用unzip命令解压oracle-xe-11.2.0-1.0.x86_64.rpm.zip

  1. [root@localhost opt]# unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
  2. Archive: oracle-xe-11.2.0-1.0.x86_64.rpm.zip
  3. creating: Disk1/
  4. creating: Disk1/upgrade/
  5. inflating: Disk1/upgrade/gen_inst.sql
  6. creating: Disk1/response/
  7. inflating: Disk1/response/xe.rsp
  8. inflating: Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm

使用rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm命令安装数据库。

  1. [root@localhost opt]# cd Disk1/
  2. [root@localhost Disk1]# ls
  3. oracle-xe-11.2.0-1.0.x86_64.rpm response upgrade
  4. [root@localhost Disk1]# rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm
  5. Preparing... ################################# [100%]
  6. /var/tmp/rpm-tmp.h5j4r0: line 257: [: 18446744073692774399: integer expression expected
  7. /var/tmp/rpm-tmp.h5j4r0: line 271: [: 18446744073692774399: integer expression expected
  8. Updating / installing...
  9. 1:oracle-xe-11.2.0-1.0 ################################# [100%]
  10. Executing post-install steps...
  11. You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.
  12. [root@localhost Disk1]#

安装完成后,按照提示配置数据库。
提示1:配置数据库需要输入时仔细点,输入错了是无法删除的
提示2:需要输入时,直接回车表示使用默认值

  1. [root@localhost Disk1]# /etc/init.d/oracle-xe configure
  2. Oracle Database 11g Express Edition Configuration
  3. -------------------------------------------------
  4. This will configure on-boot properties of Oracle Database 11g Express
  5. Edition. The following questions will determine whether the database should
  6. be starting upon system boot, the ports it will use, and the passwords that
  7. will be used for database accounts. Press <Enter> to accept the defaults.
  8. Ctrl-C will abort.
  9. Specify the HTTP port that will be used for Oracle Application Express [8080]:8021
  10. Specify a port that will be used for the database listener [1521]:
  11. Specify a password to be used for database accounts. Note that the same
  12. password will be used for SYS and SYSTEM. Oracle recommends the use of
  13. different passwords for each database account. This can be done after
  14. initial configuration:
  15. Confirm the password:
  16. Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:n
  17. Starting Oracle Net Listener...Done
  18. Configuring database...Done
  19. Starting Oracle Database 11g Express Edition instance...Done
  20. Installation completed successfully.
  21. [root@localhost Disk1]#

数据库配置期间的日志文件在$ORACLE_HOME/config/log/*.路径下,如果没有更改安装路径的话,$ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe/

2.3 配置环境变量

安装并配置Oracle 11g XE 后,在使用数据库之前需要配置环境变量。Oracle 11g XE提供了脚本,用于设置必要的环境变量。脚本
/u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh的内容如下:

  1. export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
  2. export ORACLE_SID=XE
  3. export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
  4. export PATH=$ORACLE_HOME/bin:$PATH

配置方式一:用户配置
编辑用户家目录下的配置文件.bash_profile文件(登录后生效)或者.bashrc文件(打开新shell时生效),在文件中增加以下内容:

  1. . /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh

配置方式二:全局配置
在全局配置文件~~/etc/profile~~中增加以下内容:

  • Linux 下用户自定义的环境变量最好是在 /etc/profile.d/路径下新建个.sh文件,放在新建的.sh文件中。

    /etc/profile 文件的说明中有明确说到:

    /etc/profile

    System wide environment and startup programs, for login setup

    Functions and aliases go in /etc/bashrc

    It’s NOT a good idea to change this file unless you know what you

    are doing. It’s much better to create a custom.sh shell script in

    /etc/profile.d/ to make custom changes to your environment, as this

    will prevent the need for merging in future updates.

    参考链接:Linux环境变量到底配置到哪里?

  1. #取自/u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh文件
  2. export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
  3. export ORACLE_SID=XE
  4. export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
  5. export PATH=$ORACLE_HOME/bin:$PATH

或者
/u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh复制一份,放到/etc/profile.d/路径下。

2.4 远程访问数据库管理页面

默认情况下,数据库管理页面只能本地访问。使用SQL*Plus命令行设置为可远程访问:

  1. [root@localhost ~]# sqlplus
  2. SQL*Plus: Release 11.2.0.2.0 Production on Tue Aug 17 13:32:32 2021
  3. Copyright (c) 1982, 2011, Oracle. All rights reserved.
  4. Enter user-name: system
  5. Enter password:
  6. Connected to:
  7. Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
  8. SQL> EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
  9. PL/SQL procedure successfully completed.
  10. SQL> exit;
  11. Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
  12. [root@localhost ~]#

2.5 防火墙设置

为保证oracle数据库可远程访问,关闭防火墙或者开放相应的端口。
关闭防火墙:

  1. #关闭防火墙
  2. [root@localhost ~]# systemctl stop firewalld.service
  3. #取消防火墙开机自启
  4. [root@localhost ~]# systemctl disable firewalld.service
  5. Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
  6. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  7. [root@localhost ~]#

或者
开放相应端口:

  1. #设置防火墙开机自启
  2. [root@localhost ~]# systemctl enable firewalld.service
  3. Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
  4. Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
  5. #启动防火墙
  6. [root@localhost ~]# systemctl start firewalld.service
  7. #查看已开放的端口
  8. [root@localhost ~]# firewall-cmd --list-ports
  9. #开放端口(需重启防火墙)
  10. # --zone=public 指定的zone为public
  11. # --add-port 标识添加的端口,格式为:端口/通讯协议
  12. # --permanent 永久生效
  13. [root@localhost ~]# firewall-cmd --zone=public --add-port=8021/tcp --permanent
  14. success
  15. [root@localhost ~]# firewall-cmd --zone=public --add-port=1521/tcp --permanent
  16. success
  17. #重启防火墙
  18. [root@localhost ~]# firewall-cmd --reload
  19. success
  20. #查看已开放的端口
  21. [root@localhost ~]# firewall-cmd --list-ports
  22. 8021/tcp 1521/tcp
  23. [root@localhost ~]#

3 Oracle Apex(数据库GUI管理页面)

参考链接:https://docs.oracle.com/cd/E11882_01/appdev.112/e12512/adm_login.htm#AEADM168

登录用户名(默认用户):admin
登录密码:Oracle数据库安装时你设置的密码
image.png

  • 初次登录需要重设密码(重设的密码还需要满足密码强度要求,示例:Oracle123+=)

image.png

  • 修改完密码后,使用新密码登录进入主页,可在右下角区域选择语言

image.png

4 常见问题

4.1 启动oracle

2.2 安装配置 时没有选择开机启动Oracle数据库,所以系统重启后,Oracle数据库需要手动启动。

  1. # 切换为 oracle 用户
  2. [root@localhost ~]# su - oracle
  3. # 使用 oracle 用户启动监听
  4. -bash-4.2$ lsnrctl start
  5. # 使用sys以DBA身份登录sqlplus,
  6. [root@localhost ~]# sqlplus sys as sysdba
  7. # 使用startup命令启动数据库实例
  8. SQL> startup;
  9. ORACLE instance started.
  10. Total System Global Area 409194496 bytes
  11. Fixed Size 2227000 bytes
  12. Variable Size 293602504 bytes
  13. Database Buffers 109051904 bytes
  14. Redo Buffers 4313088 bytes
  15. Database mounted.
  16. Database opened.
  17. SQL> exit
  18. Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

4.2 停止oracle

  1. # 使用sys以DBA身份登录sqlplus,
  2. [root@localhost ~]# sqlplus sys as sysdba
  3. # 使用shutdown 或者 shutdown immediate关闭数据库实例
  4. SQL> shutdown;
  5. Database closed.
  6. Database dismounted.
  7. ORACLE instance shut down.
  8. ...
  9. SQL> shutdown immediate;
  10. Database closed.
  11. Database dismounted.
  12. ORACLE instance shut down.
  13. # 停止监听
  14. [root@localhost ~]# lsnrctl stop

4.3 启动监听报错,TNS-12555: TNS:permission denied

  1. [root@localhost ~]# lsnrctl start
  2. LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 17-AUG-2021 15:26:17
  3. Copyright (c) 1991, 2011, Oracle. All rights reserved.
  4. Starting /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr: please wait...
  5. TNSLSNR for Linux: Version 11.2.0.2.0 - Production
  6. System parameter file is /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
  7. Log messages written to /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/localhost/listener/alert/log.xml
  8. Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
  9. TNS-12555: TNS:permission denied
  10. TNS-12560: TNS:protocol adapter error
  11. TNS-00525: Insufficient privilege for operation
  12. Linux Error: 1: Operation not permitted
  13. Listener failed to start. See the error message(s) above...
  14. [root@localhost ~]#

提示没权限,切换oracle用户启动监听:

  1. [root@localhost ~]# su - oracle
  2. Last login: Tue Aug 17 14:51:05 CST 2021
  3. -bash-4.2$ lsnrctl start
  4. LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 17-AUG-2021 15:28:57
  5. Copyright (c) 1991, 2011, Oracle. All rights reserved.
  6. Starting /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr: please wait...
  7. TNSLSNR for Linux: Version 11.2.0.2.0 - Production
  8. System parameter file is /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
  9. Log messages written to /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/localhost/listener/alert/log.xml
  10. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
  11. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.102)(PORT=1521)))
  12. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
  13. STATUS of the LISTENER
  14. ------------------------
  15. Alias LISTENER
  16. Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
  17. Start Date 17-AUG-2021 15:28:59
  18. Uptime 0 days 0 hr. 0 min. 0 sec
  19. Trace Level off
  20. Security ON: Local OS Authentication
  21. SNMP OFF
  22. Default Service XE
  23. Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
  24. Listener Log File /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/localhost/listener/alert/log.xml
  25. Listening Endpoints Summary...
  26. (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
  27. (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.102)(PORT=1521)))
  28. Services Summary...
  29. Service "PLSExtProc" has 1 instance(s).
  30. Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
  31. The command completed successfully
  32. -bash-4.2$

4.4 数据库可视化工具连接报错,ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

https://stackoverflow.com/questions/10786782/ora-12514-tnslistener-does-not-currently-know-of-service-requested-in-connect-d

原因:
oracle数据库中有监听和实例的概念,监听用来接收用户请求,实例是实际的数据库。实例启动后会向监听进行注册,监听收到请求后会从已注册的实例中进行匹配,选择具体的实例进行处理。
报错原因是oracle监听接收请求后,找不到对应的实例,无法处理请求。
实例启动后没有动态向监听注册。
解决:
静态注册实例,即在listener.ora文件中配置好数据库实例
listener.oratnsnames.ora文件的路径:/u01/app/oracle/product/11.2.0/xe/network/admin/

  1. # listener.ora Network Configuration File:
  2. SID_LIST_LISTENER =
  3. (SID_LIST =
  4. (SID_DESC =
  5. (SID_NAME = PLSExtProc)
  6. (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
  7. (PROGRAM = extproc)
  8. )
  9. #静态注册XE实例
  10. (SID_DESC =
  11. (SID_NAME = XE)
  12. (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
  13. )
  14. )
  15. LISTENER =
  16. (DESCRIPTION_LIST =
  17. (DESCRIPTION =
  18. (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
  19. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521))
  20. )
  21. )

5 其他相关

5.1 创建/修改数据库用户信息

参考链接: Oracle Database XE 11gR2 自带的用户,新建用户,修改用户密码 oracle 给表空间增加多个数据文件

  • 新建用户
    1. 使用sqlplus 登录数据库管理员账号 ```bash [root@localhost ~]# sqlplus

SQL*Plus: Release 11.2.0.2.0 Production on Sat Nov 27 14:58:15 2021

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

Enter user-name: sys as sysdba Enter password:

Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL>


bash-4.2$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Tue Dec 7 10:52:49 2021

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

Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL>

  1. 2. 创建表空间
  2. ```plsql
  3. --查看当前有哪些表空间
  4. select * from dba_tablespaces;
  5. --查看表空间文件路径
  6. select * from dba_data_files;
  7. --创建表空间
  8. create tablespace demo_data datafile '/u01/app/oracle/oradata/XE/demo_data.dbf' size 500m autoextend on next 100m;
  9. --为表空间添加多个.dbf文件
  10. alter tablespace demo_data add datafile '/u01/app/oracle/oradata/XE/demo_data2.dbf' size 500m autoextend on next 100m;
  11. alter tablespace demo_data add datafile '/u01/app/oracle/oradata/XE/demo_data3.dbf' size 500m autoextend on next 100m;
  1. 删除表空间 ```plsql —删除空的表空间,但是不包含物理文件 drop tablespace tablespace_name;

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

—删除空表空间,包含物理文件 drop tablespace tablespace_name including datafiles;

—删除非空表空间,包含物理文件 drop tablespace tablespace_name including contents and datafiles;

—如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

  1. 4. 创建用户
  2. username: test01<br />password: 123456
  3. ```plsql
  4. --创建用户时就指定用户的表空间
  5. create user test01 identified by 123456 default tablespace demo_data;
  6. --创建用户时不指定表空间,创建完成后再指定
  7. create user test01 identified by 123456;
  8. alert user test01 default tablespace demo_data;
  • 对用户授权/取消授权

    1. --授权
    2. grant connect,resource,dba to test01;
    3. --取消授权
    4. revoke dba from test01;
  • 修改用户密码

username: test01
password: abcdefg

  1. alter user test01 identified by abcdefg;
  • 删除用户及用户下所有对象
    1. drop user test01 cascade;