环境
linux虚拟机
lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.8 (Final)
Release: 6.8
Codename: Final
安装依赖
更新yum
# yum update -y
安装必要组件
# yum install -y binutils.x86_64 compat-libcap1.x86_64 gcc.x86_64 gcc-c++.x86_64 glibc.i686 glibc.x86_64 glibc-devel.i686 glibc-devel.x86_64 ksh compat-libstdc++-33 libaio.i686 libaio.x86_64 libaio-devel.i686 libaio-devel.x86_64 libgcc.i686 libgcc.x86_64 libstdc++.i686 libstdc++.x86_64 libstdc++-devel.i686 libstdc++-devel.x86_64 libXi.i686 libXi.x86_64 libXtst.i686 libXtst.x86_64 make.x86_64 sysstat.x86_64 zip unzip
修改内核参数
vim /etc/sysctl.conf
#oracle
kernel.shmmni=4096
kernel.sem=250 32000 100 128
fs.file-max=6815744
fs.aio-max-nr=1048576
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
建立用户和组
# groupadd oinstall
# groupadd dba
# groupadd oper
# useradd -g oinstall -G dba,oper oracle
# passwd oracle
创建安装目录
# mkdir -p /u01/app/oracle
# chown -R oracle:oinstall /u01/app
# chmod -R 775 /u01
限制资源参数
session required pam_limits.so #添加
修改文件限制
#oracle
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
修改环境变量
su oracle
vim .bash_profile
umask 022
export ORACLE_BASE=/u01/app/oracle
source .bash_profile
解压
unzip linuxx64_12201_database.zip
安装
安装为图形化界面安装,
若未安装xwindow则安装
yum -y groupinstall Desktop
yum -y groupinstall "X Window System"
也可以添加中文支持,重启选择中文进入即可
yum -y groupinstall chinese-support
xhost +//以root用户在图形化界面操作
su - oracle//切换oracle用户
exportDISPLAY=:0.0//调整分辨率
./database/runInstaller //也可以重启登入oracle用户开始安装
注:此次安装只为后面c++程序测试,所以均为最简单安装
安全更新邮箱不填,不接受安全更新
系统类选择服务器类
数据库选择单例版本选择企业版
安装类型选择典型安装,此处需要输入口令,必须有大小写字母及数字
开始安装出现弹窗以root身份执行完脚本关闭即可,
因为虚拟机/tmp交换空间较小此处出现警告忽略了继续安装(不影响后面测试)
创建监听
vim .bash_profie //添加
export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
source .bash_profile
运行netca
此后对话框全部选择默认选项
port:1521
监听程序命:LISTENER
创建数据库
运行dbca 此后选择典型安装输入口令即可
完成后使用命令行登陆
sqlplus / as sysdba
SQL>
创建用户
SQL> create user hww identified by hww;
User created.
授权登陆连接管理员权限
SQL> grant connect, resource, dba to hww;
Grant succeeded.
查看哪些用户具有管理员权限
SQL> select * from dba_role_privs where granted_role='DBA' ;
GRANTEE
--------------------------------------------------------------------------------
GRA ADM DEL DEF COM INH
--- --- --- --- --- ---
HWW
DBA NO NO YES NO NO
SYSTEM
DBA NO NO YES YES YES
SYS
DBA YES NO YES YES YES
使用C++连接
需要rpm包
# rpm -qa|grep oracle
oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64
oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64
下载https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
改变临时环境变量
export PATH=/usr/include/oracle/12.1/client64/
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
测试代码
#include
#define LINUXOCCI //避免函数重定义错误
#include
using namespace std;
using namespace oracle::occi;
int main()
{
Environment *env=Environment::createEnvironment(Environment::DEFAULT);
cout<<"success"< string name = "hww"; string pass = "hww"; string srvName = "192.168.86.201:1521/orcl"; //string method = "select * from all_users"; string method = "select * from dba_role_privs where granted_role='DBA'"; string strTemp; try { Connection *conn = env->createConnection(name, pass,srvName); cout<<"conn success"< Statement *pStmt = conn->createStatement(method) ResultSet *pRs = pStmt->executeQuery() while(pRs->next()) { strTemp = pRs->getString(1); cout< } pStmt->closeResultSet(pRs); conn->terminateStatement(pStmt); env->terminateConnection(conn); } catch(SQLException e) { cout< } Environment::terminateEnvironment(env); cout<<"end!"< return 0; } [root@heweiwei oracle]# g++ -o test -I /usr/include/oracle/12.1/client64/ -L/usr/lib/oracle/12.1/client64/lib/ oraclelib_test.cpp -lclntsh -locci -lmql1 -lipc1 -lnnz12 -lons -lclntshcore -Wall -O -g [root@heweiwei oracle]# ./test success conn success HWW SYSTEM SYS end! [root@heweiwei oracle]# 从结果看和之前登入数据库查到的结果相同测试完成 https://www.cnblogs.com/xzjf/p/8301109.html http://blog.51cto.com/13643643/2140547 https://www.cnblogs.com/xufeiyang/archive/2012/08/24/2654550.html编译
运行
参考