rails支持oracle数据库连接
一、下载安装(解压)依赖包
下载 instantclient-basic, instantclient-sqlplus and instantclient-sdk zip archives 然后解压到 instantclient_12.1 文件夹下面(文件名字以实际名字为主).
然后把文件移动到 /opt/oracle/instantclient_12.1
下载需要登录oracle账号,并且要同意协议,直接点击下面链接无法下载
如遇版本修改,连接可能失效,请在官网自行搜索下载
32位地址
http://www.oracle.com/technetwork/topics/linuxsoft-082809.html
要选择好
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
sudo mkdir -p /opt/oracle
sudo cd /opt/oracle
sudo unzip /tmp/instantclient-basic-linux-12.1.0.2.0.zip
sudo unzip /tmp/instantclient-sqlplus-linux-12.1.0.1.0.zip
sudo unzip /tmp/instantclient-sdk-linux-12.1.0.1.0.zip
sudo apt-get install libaio1
sudo cd instantclient_12_1
sudo ln -s libclntsh.so.12.1 libclntsh.so
二、设置环境变量
vim ~/.bashrc
# 添加
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12.1
source ~/.bashrc
其他、遇到的某一些问题
[b]oracle汉字显示乱码
解决方案:[/b]
vim ~/.bashrc
添加
export NLS_LANG=AMERICAN_AMERICA.UTF8
source ~/.bashrc
=============
如果你没有安装上面依赖环境,会遇到下面问题
An error occurred while installing ruby-oci8 (2.1.8), and
Bundler cannot continue.
Make sure that `gem install ruby-oci8 -v '2.1.8'` succeeds
before bundling.
问题
checking for LP64... no
三、rails里面的gem安装
Gilefile里面添加
gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
四、数据库配置文件
development:
adapter: oracle_enhanced
host: *.*.*.*
database: database
port: 1521
username: username
password: password
pool: 5
timeout: 5000
encoding: utf-8