Ubuntu下rails程序链接oracle数据库
rails支持oracle数据库连接
一、下载安装(解压)依赖包
下载instantclient-basic,instantclient-sqlplusandinstantclient-sdkziparchives然后解压到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
sudomkdir-p/opt/oracle
sudocd/opt/oracle
sudounzip/tmp/instantclient-basic-linux-12.1.0.2.0.zip
sudounzip/tmp/instantclient-sqlplus-linux-12.1.0.1.0.zip
sudounzip/tmp/instantclient-sdk-linux-12.1.0.1.0.zip
sudoapt-getinstalllibaio1
sudocdinstantclient_12_1
sudoln-slibclntsh.so.12.1libclntsh.so
如果是mac,需要把最后一个改为
ln-slibclntsh.dylib.12.1libclntsh.dylib
二、设置环境变量
vim~/.bashrc
#添加
exportLD_LIBRARY_PATH=/opt/oracle/instantclient_12_1
source~/.bashrc
如果是mac,没有mnt目录,需要自己弄,设置如下
exportOCI_DIR=/目录/oracle/instantclient_12_1
其他、遇到的某一些问题
[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
[b]Mac下面启动的问题[b]
问题:gem安装好之后,不能连接数据库,报错
oci8.c:601:in oci8lib_230.bundle: ORA-21561: OID generation failed (OCIError)
解决方法:
echo "127.0.0.1 $(hostname)" | sudo tee -a /etc/hosts