$su -
~# apt-get install ruby-dev
# gem install mysql2 -- --with-mysql-config=/opt/mysql/bin/mysql_config
Building native extensions.
This could take a while...
Successfully installed mysql2-0.3.17
1 gem installed
Installing ri documentation for mysql2-0.3.17...
Installing RDoc documentation for mysql2-0.3.17...
:~# gem install mysql -- --with-mysql-config=/opt/mysql/bin/mysql_config
Fetching: mysql-2.9.1.gem (100%)
Building native extensions.
This could take a while...
Successfully installed mysql-2.9.1
1 gem installed
Installing ri documentation for mysql-2.9.1...
Installing RDoc documentation for mysql-2.9.1...
mysql测试代码
require 'mysql'
begin
rescue Mysql::Error => e
ensure
end
mysql2测试代码
require 'mysql2'
client = Mysql2::Client.new(:host => "127.0.0.1", :username => "用户名",:password=>"密码",:database=>"数据库名")
results = client.query("select * from 表名");
results.each do |hash|
end
(pg)访问postgreSQL
gem install pg -- --with-pg-config=/opt/PostgreSQL/9.3/bin/pg_config
require 'pg'
conn = PG.connect( :dbname => '数据库名', :host => '主机名', :port => 5432,:user => '用户名' , :password => '密码' )
results = conn.exec( "SELECT * from 表名" )
results.each do |hash|
end