Ruby實踐—連線Mysql

meteorlwj發表於2010-04-27

安裝環境:

OS:Windows XP

Ruby: Ruby1.9.1

Mysql: Mysql5.1.46 (username/password: root/root  port:3306)

Ruby-Mysql Driver: mysql-2.8.1-x86-mswin32.gem

(注:用2.7.3版本的驅動在測試時會出現 require"mysql",找不到指定模組 錯誤)

IDE:RubyMine2.0.1

 

安裝Ruby,RubyMine,Mysql的事項在這裡就不多說了,提一下安裝驅動的步驟

1)在Mysql安裝目錄的 bin 目錄下,找到 ibmySQL.dll ,將該檔案複製到 Ruby 安裝目錄的 bin 目錄中

2)http://rubyforge.org/frs/?group_id=1598,下載 mysql-2.8.1-x86-mswin32.gem,這是 mysql_Ruby驅動程式。

       命令列,進入該檔案所在目錄,執行 gem install mysql-2.8.1-x86-mswin32.gem ,安裝成功即可。

     

 

建立Ruby測試類

MysqlTest.rb

 

測試結果:

C:/Ruby19/bin/ruby.exe -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) E:/Ruby/Test/com.crystal/mysql_test.rb
Test Mysql....
localhost
Create Table........1 rows were inserted
===Select Data===
Tom,
==================
Server version: 5.1.46-community
Close Connection.......

Process finished with exit code 0

 

檢視資料庫test

 

 

相關文章