Rails连接oracle配置
参考文档:https://chinacheng.iteye.com/blog/2244282
1.下载oracle安装包
下载需要登录oracle账号,并且要同意协议,直接点击下面链接无法下载
如遇版本修改,连接可能失效,请在官网自行搜索下载
oracle账号密码
https://login.oracle.com/mysso/signon.jsp
1209374096@qq.com Lmg1209374096
要选择好版本
64位下载地址
http://download.oracle.com/otn/linux/instantclient/121020/instantclient-basic-linux.x64-12.1.0.2.0.zip
http://download.oracle.com/otn/linux/instantclient/121010/instantclient-sqlplus-linux.x64-12.1.0.1.0.zip
http://download.oracle.com/otn/linux/instantclient/121010/instantclient-sdk-linux.x64-12.1.0.1.0.zip
32位地址
http://download.oracle.com/otn/linux/instantclient/121020/instantclient-sdk-linux-12.1.0.2.0.zip
http://download.oracle.com/otn/linux/instantclient/121020/instantclient-sqlplus-linux-12.1.0.2.0.zip
http://download.oracle.com/otn/linux/instantclient/121020/instantclient-basic-linux-12.1.0.2.0.zip
64位安装步骤
2.将安装包上传到 /tmp 目录下
cd /opt
sudo mkdir oracle
cd oracle
sudo unzip /tmp/instantclient-basic-linux.x64-12.1.0.2.0.zip
sudo unzip /tmp/instantclient-sqlplus-linux.x64-12.1.0.1.0.zip
sudo unzip /tmp/instantclient-sdk-linux.x64-12.1.0.1.0.zip
sudo apt-get install libaio1
cd instantclient_12_1
sudo ln -s libclntsh.so.12.1 libclntsh.so
3.设置环境变量
cd ~
vi ~/.bashrc
# 添加
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_1
source ~/.bashrc
4.安装Gem包
Gilefile里面添加
gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter'
5.执行 bundle install
6.修改config/database.yml
oracle_development: #名字可自定义,但是不能重复。
adapter: oracle_enhanced
username: A8USER
database: oaorcl
password: Admin123456
host: 192.168.100.114
port: 1521 # Oracle DB 的端口号,如果为 Mysql 则不用写。
encoding: utf8
7.添加model映射表,在app/models新增d_oa_database.rb
class DOaDatabase < ActiveRecord::Base
self.abstract_class = true
establish_connection :oracle_development # oracle_development 为database.yml文件中添加的第二个 DB 配置的名字
self.table_name = "FORMMAIN_5399" #表名
end
AMERICAN_AMERICA.UTF8