Checking Temp space: must be greater than 120 MB. Actual 10589 MB Passed Checking swap space: must be greater than 150 MB. Actual 2047 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2023-12-11_12-12-56PM. Please wait ...[oracle@node1 database]$ [WARNING] [INS-32055] The Central Inventory is located in the Oracle base. CAUSE: The Central Inventory is located in the Oracle base. ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory. [WARNING] [INS-32055] The Central Inventory is located in the Oracle base. CAUSE: The Central Inventory is located in the Oracle base. ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory. You can find the log of this install session at: /usr/local/oracle/inventory/logs/installActions2023-12-11_12-12-56PM.log
# bash /usr/local/oracle/inventory/orainstRoot.sh Changing permissions of /usr/local/oracle/inventory. Adding read,write permissions for group. Removing read,write,execute permissions for world.
Changing groupname of /usr/local/oracle/inventory to oinstall. The execution of the script is complete. # bash /usr/local/oracle/product/11.2.0/root.sh Check /usr/local/oracle/product/11.2.0/install/root_node1_2023-03-01_12-10-31.log for the output of root script
TNSLSNR for Linux: Version 11.2.0.1.0 - Production Log messages written to /usr/local/oracle/diag/tnslsnr/node1/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=node1)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 01-MAR-2023 12:48:53 Uptime 0 days 0 hr. 0 min. 20 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Log File /usr/local/oracle/diag/tnslsnr/node1/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=node1)(PORT=1521))) The listener supports no services The command completed successfully
关闭端口监听(暂不操作):
1 2 3 4 5 6 7 8
$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-OCT-2022 02:02:57
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) The command completed successfully
SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 1 12:51:53 2023
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL>
启动实例:
1 2 3 4 5 6 7 8 9
SQL> startup ORACLE instance started.
Total System Global Area 835104768 bytes Fixed Size 2217952 bytes Variable Size 490735648 bytes Database Buffers 335544320 bytes Redo Buffers 6606848 bytes ORA-01102: cannot mount database in EXCLUSIVE mode
遇到报错,关闭数据库,新建窗口进行修改:
1 2 3 4 5
SQL> shutdown immediate ORA-01507: database not mounted
ORACLE instance shut down.
参考启动问题处理,处理后使用oracle用户启动实例:
1 2 3 4 5 6 7 8 9 10
SQL> startup ORACLE instance started.
Total System Global Area 835104768 bytes Fixed Size 2217952 bytes Variable Size 490735648 bytes Database Buffers 335544320 bytes Redo Buffers 6606848 bytes Database mounted. Database opened.
查看版本:
1 2 3 4 5 6 7 8 9
SQL> select * from v$version;
BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
开启scott用户,设置密码:userpwd:
1 2 3 4 5 6 7
SQL> alter user scott account unlock;
User altered.
SQL> alter user scott identified by userpwd;
User altered.
退出sql:
1 2 3 4
SQL> exit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Oracle Label Security, OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
附:启动问题处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# MEMORY_TARGET not supported on this system解决方法 mount -o remount,size=3G /dev/shm/
# cannot mount database in EXCLUSIVE mode解决方案 \rm /usr/local/oracle/product/11.2.0/dbs/lkORCL
# error in identifying control file解决方案,ipcrm的参数是第一个key的semid ipcs -s ipcrm -s 17 ipcs -m
# database not open解决方法 alter database open; connection lost contact sqlplus / as sysdba
# 重新登录 程序连接不到Oracle,需要配置/etc/hosts,重启监听
python操作oracle数据库
node1
切换oracle用户,使用scott用户登录oracle数据库:
1 2 3 4 5 6 7 8 9 10 11 12 13
$ sqlplus scott/userpwd
SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 1 12:55:33 2023
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Oracle Label Security, OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
SQL>
创建t1表:
1 2 3
SQL> create table t1(id int not null, name varchar(8) not null);
Table created.
t1表插入数据:
1 2 3 4 5 6 7 8 9
SQL> insert into t1(id, name) values (1, 'student');
SQL> quit Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Oracle Label Security, OLAP, Data Mining, Oracle Database Vault and Real Application Testing options
安装oracle基础包:
1 2
$ cd /usr/local/oracle/ $ unzip instantclient-basic-linux.x64-11.2.0.4.0.zip
切换root用户,配置环境变量:
1 2 3 4
# vim /root/.bashrc # 尾行,添加配置: export ORACLE_HOME=/usr/local/oracle/instantclient_11_2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
# vim /tmp/oracle_test.py import cx_Oracle dsn = cx_Oracle.makedsn('10.80.10.1', '1521', 'orcl') db = cx_Oracle.connect('scott', 'userpwd', dsn) cr=db.cursor() sql = 'select * from t1' cr.execute(sql) rs=cr.fetchall() for x in rs: print(x)
测试python脚本:
1 2
# python /tmp/oracle_test.py (3, 'student')
1 2 3 4 5
没有加载环境变量,执行python脚本会报错: `Traceback (most recent call last): File "/tmp/oracle_test.py", line 3, in <module> db = cx_Oracle.connect('scott', 'userpwd', dsn) cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux for help`
切换oracle用户,数据库添加数据:
1 2 3 4 5 6 7 8 9 10 11
$ sqlplus scott/userpwd
SQL> insert into t1(id, name) values (2, 'teacher');