Ubuntu下rails程序链接oracle数据库

[b]rails支持oracle数据库连接[/b]

一、下载安装(解压)依赖包

下载 instantclient-basic, instantclient-sqlplus and instantclient-sdk zip archives 然后解压到 instantclient_12.1 文件夹下面(文件名字以实际名字为主).
然后把文件移动到 /opt/oracle/instantclient_12.1

[b][color=red]下载需要登录oracle账号,并且要同意协议,直接点击下面链接无法下载[/color][/b]
[b][color=red]如遇版本修改,连接可能失效,请在官网自行搜索下载[/color][/b]
32位地址
[url]http://www.oracle.com/technetwork/topics/linuxsoft-082809.html[/url]

要选择好
64位下载地址
[url]http://download.oracle.com/otn/linux/instantclient/121020/instantclient-basic-linux.x64-12.1.0.2.0.zip[/url]
[url]http://download.oracle.com/otn/linux/instantclient/121010/instantclient-sqlplus-linux.x64-12.1.0.1.0.zip[/url]
[url]http://download.oracle.com/otn/linux/instantclient/121010/instantclient-sdk-linux.x64-12.1.0.1.0.zip[/url]

32位地址
[url]http://download.oracle.com/otn/linux/instantclient/121020/instantclient-sdk-linux-12.1.0.2.0.zip[/url]
[url]http://download.oracle.com/otn/linux/instantclient/121020/instantclient-sqlplus-linux-12.1.0.2.0.zip[/url]
[url]http://download.oracle.com/otn/linux/instantclient/121020/instantclient-basic-linux-12.1.0.2.0.zip[/url]

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


如果是mac,需要把最后一个改为

ln -s libclntsh.dylib.12.1 libclntsh.dylib


[b]二、设置环境变量[/b]


vim ~/.bashrc
# 添加
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_1

source ~/.bashrc


如果是mac,没有mnt目录,需要自己弄,设置如下

export OCI_DIR=/目录/oracle/instantclient_12_1


[b]其他、遇到的某一些问题[/b]


[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


[b]三、rails里面的gem安装[/b]

Gilefile里面添加

gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'


[b]四、数据库配置文件[/b]

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

你可能感兴趣的:(rails,linux,oracle,rails)