Linux:
# 创建用户和组
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
# 创建目录
mkdir -p /u01/app/oracle/product/19.0.0/dbhome_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01
# 设置内核参数(以CentOS/RHEL为例)
vi /etc/sysctl.conf
# 添加以下内容:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
sysctl -p
bash
unzip LINUX.X64_193000_db_home.zip -d /u01/app/oracle/product/19.0.0/dbhome_1
bash
vi ~/.bash_profile
# 添加以下内容:
export ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
bash
cd $ORACLE_HOME
./runInstaller
bash
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/19.0.0/dbhome_1/root.sh
-- 连接数据库
sqlplus / as sysdba
-- 创建表空间
CREATE TABLESPACE users DATAFILE '/u01/app/oracle/oradata/orcl/users01.dbf' SIZE 100M AUTOEXTEND ON;
-- 创建用户
CREATE USER demo IDENTIFIED BY demo DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
-- 授予权限
GRANT CONNECT, RESOURCE TO demo;
配置监听器(listener.ora)
cd $ORACLE_HOME/network/admin
vi listener.ora
示例内容:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
配置TNS名称(tnsnames.ora)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
启动监听器
lsnrctl start
lsnrctl status
vi /etc/oratab
# 修改最后一行:
orcl:/u01/app/oracle/product/19.0.0/dbhome_1:Y
vi /etc/init.d/oracle
# 添加启动脚本(内容略)
chmod 755 /etc/init.d/oracle
chkconfig --add oracle
连接测试:
sqlplus system/密码@orcl
查询数据库状态:
SELECT name, open_mode FROM v$database;
SELECT * FROM v$version;
创建测试表并插入数据:
CONNECT demo/demo
CREATE TABLE test (id NUMBER, name VARCHAR2(50));
INSERT INTO test VALUES (1, 'Oracle安装测试');
COMMIT;
SELECT * FROM test;
ORA-12514: TNS:listener does not currently know of service requested
ORA-01034: ORACLE not available
sqlplus / as sysdba
后运行STARTUP
安装过程中出现空间不足
bash
dd if=/dev/zero of=/swapfile bs=1M count=2048
mkswap /swapfile
swapon /swapfile
图形界面无法启动(Linux)
bash
yum install libXext libXtst libX11
bash
export DISPLAY=:0.0
xhost +
完成以上步骤后,您应该已经成功安装并配置了Oracle数据库环境。根据实际需求,您可能还需要进行性能调优、备份策略配置等进一步操作。