如何配置centos的sqlplus
Prerequisites
Before configuring SQL*Plus on CentOS, ensure your system meets the following requirements:
- A clean CentOS system (7 or 8) with root or sudo privileges.
- Basic package dependencies installed:
sudo yum install -y libaio libaio-devel wget unzip
(these are required for Oracle Instant Client to function properly).
Step 1: Download Oracle Instant Client Packages
Oracle Instant Client is the lightweight, standalone package needed to run SQL*Plus. Visit the Oracle Instant Client Downloads page and download the following RPM packages (replace 21.6.0.0.0
with your desired version):
oracle-instantclient-basic-21.6.0.0.0-1.x86_64.rpm
(core client files)oracle-instantclient-sqlplus-21.6.0.0.0-1.x86_64.rpm
(SQL*Plus utility).
Step 2: Install Oracle Instant Client via Yum
Navigate to the directory where the RPMs were downloaded and install them using yum (this resolves dependencies automatically):
cd /path/to/downloaded/rpms
sudo yum localinstall oracle-instantclient-basic-*.rpm oracle-instantclient-sqlplus-*.rpm
Yum will install the packages to /usr/lib/oracle/<
version>
/client64
(e.g., /usr/lib/oracle/21/client64
).
Step 3: Configure Environment Variables
Edit your user’s .bashrc
file (or /etc/profile
for system-wide access) to set critical environment variables:
nano ~/.bashrc
Add the following lines (adjust paths if your installation differs):
export ORACLE_HOME=/usr/lib/oracle/21/client64 # Path to Instant Client
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH # Link to client libraries
export PATH=$ORACLE_HOME/bin:$PATH # Add SQL*Plus to PATH
Save the file and apply changes:
source ~/.bashrc
Verify the variables are set correctly:
echo $ORACLE_HOME # Should show the client path
echo $PATH # Should include $ORACLE_HOME/bin
```.
**Step 4: Verify SQL*Plus Installation**
Run the following command to confirm SQL*Plus is accessible:
```bash
sqlplus -v
You should see output like:
SQL*Plus: Release 21.0.0.0.0 - Production on Wed Sep 25 14:30:00 2025
Version 21.6.0.0.0
This confirms SQL*Plus is installed and ready to use.
Optional Step 5: Configure TNSNAMES.ORA for Remote Connections
If you need to connect to a remote Oracle database (instead of using easy connect syntax username/password@host:port/service
), create a tnsnames.ora
file:
sudo mkdir -p $ORACLE_HOME/network/admin # Create directory if it doesn’t exist
sudo nano $ORACLE_HOME/network/admin/tnsnames.ora
Add an entry for your database (replace placeholders with actual values):
MYDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db.example.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.example.com)
)
)
Save the file. Now you can connect using:
sqlplus username/password@MYDB
```.
**Optional Step 6: Enhance SQL*Plus Experience**
- **Alias for rlwrap**: Install `rlwrap` to enable command history and line editing in SQL*Plus:
```bash
sudo yum install -y rlwrap
echo "alias sqlplus='rlwrap sqlplus'" >
>
~/.bashrc
source ~/.bashrc
- Customize Output: Download
glogin.sql
(a SQL*Plus script) to set default formatting:
This script sets preferences like column width and timestamp display.wget https://raw.githubusercontent.com/oracle/Oracle-SQLPlus-Tools/master/glogin.sql mv glogin.sql $ORACLE_HOME/sqlplus/admin/
Troubleshooting Tips
- “sqlplus: command not found”: Verify
PATH
includes$ORACLE_HOME/bin
and runsource ~/.bashrc
again. - Library Errors: Ensure
libaio
andlibaio-devel
are installed (step 1). - Connection Failures: Double-check TNS entries (if using
tnsnames.ora
) or easy connect syntax (host/port/service).
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 如何配置centos的sqlplus
本文地址: https://pptw.com/jishu/717502.html