Oracle on Rails
#如果生产环境使用Oracle,则需要以下操作
cd ~
#instance client必须
wget http://cloud.github.com/downloads/saberma/saberma.github.com/oracle-instantclient-basic_10.2.0.3-2_i386.deb
sudo dpkg -i oracle-instantclient-basic_10.2.0.3-2_i386.deb
wget http://cloud.github.com/downloads/saberma/saberma.github.com/oracle-instantclient-devel_10.2.0.3-2_i386.deb
sudo dpkg -i oracle-instantclient-devel_10.2.0.3-2_i386.deb
#非必须,sqlplus用于调试是否能正常连接
wget http://cloud.github.com/downloads/saberma/saberma.github.com/oracle-instantclient-sqlplus_10.2.0.3-2_i386.deb
sudo dpkg -i oracle-instantclient-sqlplus_10.2.0.3-2_i386.deb
#设置client路径
export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib/
#设置客户端编码(重要!否则会乱码)
export NLS_LANG=AMERICAN_AMERICA.UTF8
#以上参数设置要放于全局设置文件中
echo "export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib/" >> ~/.bashrc
echo "export NLS_LANG=AMERICAN_AMERICA.UTF8" >> ~/.bashrc
#测试sqlplus能连接到Oracle服务器
#sqlplus myuser/mypassword@//myserver/mydatabase.mydomain.com
sqlplus zbs_ciis/zbs@//192.168.1.29/orcl
desc users;
#正常的话应能返回users表结构
#安装ruby-oci8所需包
sudo apt-get install libaio1
#安装ruby-oci8,注意不能使用sudo,否则无法正常获取LD_LIBRARY_PATH参数
gem install ruby-oci8 --no-ri --no-rdoc --version 1.0.6
#注意,如果是mac平台,则安装ruby-oci8前先定义以下参数,否则mkmf.log会报
#ld: warning: in /usr/local/oracle/instantclient/libclntsh.dylib, file is not of required architecture
#Undefined symbols for architecture i386:
# "_OCIInitialize", referenced from:
# _OCIInitialize$non_lazy_ptr in cc1EmgZD.o
#ld: symbol(s) not found for architecture i386
export ARCHFLAGS="-arch x86_64"
#一定要注意cpu的类型是intel(32bit?64bit?)还是ppc的,下载时要区分
#测试
irb
require 'rubygems'
require 'oci8'
#不报错,则表示直连正常
OCI8.new('ciis', 'ciis', '//192.168.1.29:1521/orcl')
#安装rails数据库适配器
sudo gem install saberma-activerecord-oracle_enhanced-adapter-nvarchar2 --no-ri --no-rdoc
#另外,数据库的IP地址、用户名密码等在config/database.yml中配置
#如果生产环境使用Oracle,则需要以下操作
cd ~
#instance client必须
wget http://cloud.github.com/downloads/saberma/saberma.github.com/oracle-instantclient-basic_10.2.0.3-2_i386.deb
sudo dpkg -i oracle-instantclient-basic_10.2.0.3-2_i386.deb
wget http://cloud.github.com/downloads/saberma/saberma.github.com/oracle-instantclient-devel_10.2.0.3-2_i386.deb
sudo dpkg -i oracle-instantclient-devel_10.2.0.3-2_i386.deb
#非必须,sqlplus用于调试是否能正常连接
wget http://cloud.github.com/downloads/saberma/saberma.github.com/oracle-instantclient-sqlplus_10.2.0.3-2_i386.deb
sudo dpkg -i oracle-instantclient-sqlplus_10.2.0.3-2_i386.deb
#设置client路径
export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib/
#设置客户端编码(重要!否则会乱码)
export NLS_LANG=AMERICAN_AMERICA.UTF8
#以上参数设置要放于全局设置文件中
echo "export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib/" >> ~/.bashrc
echo "export NLS_LANG=AMERICAN_AMERICA.UTF8" >> ~/.bashrc
#测试sqlplus能连接到Oracle服务器
#sqlplus myuser/mypassword@//myserver/mydatabase.mydomain.com
sqlplus zbs_ciis/zbs@//192.168.1.29/orcl
desc users;
#正常的话应能返回users表结构
#安装ruby-oci8所需包
sudo apt-get install libaio1
#安装ruby-oci8,注意不能使用sudo,否则无法正常获取LD_LIBRARY_PATH参数
gem install ruby-oci8 --no-ri --no-rdoc --version 1.0.6
#注意,如果是mac平台,则安装ruby-oci8前先定义以下参数,否则mkmf.log会报
#ld: warning: in /usr/local/oracle/instantclient/libclntsh.dylib, file is not of required architecture
#Undefined symbols for architecture i386:
# "_OCIInitialize", referenced from:
# _OCIInitialize$non_lazy_ptr in cc1EmgZD.o
#ld: symbol(s) not found for architecture i386
export ARCHFLAGS="-arch x86_64"
#一定要注意cpu的类型是intel(32bit?64bit?)还是ppc的,下载时要区分
#测试
irb
require 'rubygems'
require 'oci8'
#不报错,则表示直连正常
OCI8.new('ciis', 'ciis', '//192.168.1.29:1521/orcl')
#安装rails数据库适配器
sudo gem install saberma-activerecord-oracle_enhanced-adapter-nvarchar2 --no-ri --no-rdoc
#另外,数据库的IP地址、用户名密码等在config/database.yml中配置