歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在64位Windows+ruby2.0下安裝MySQL2

在64位Windows+ruby2.0下安裝MySQL2

日期:2017/2/28 14:33:24   编辑:Linux教程

重要文章閱讀:Ruby入門--Linux/Windows下的安裝、代碼開發及Rails實戰 http://www.linuxidc.com/Linux/2014-04/100242.htm

Ruby on rails初體驗系列文章:

http://www.linuxidc.com/Linux/2014-04/100245.htm
http://www.linuxidc.com/Linux/2014-04/100246.htm
http://www.linuxidc.com/Linux/2014-04/100247.htm

1. 環境

Windows server 2008 64bit
Mysql server 5.6
Ruby 2.0 64bit
DevKit

2. 第一次安裝

開始按照網上教程,安裝了mysql2

gem install mysql2 — ‘–with-mysql-lib=”C:\Program Files\MySQL\MySQL Server 5.6\lib” –with-mysql-include=”C:\Program Files\MySQL\MySQL Server 5.6\include”‘

安裝過程很順利,暗自慶幸。。。

第一次運行,出LoadError:

C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require
‘: 126: 找不到指定的模塊。 – C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.
3.13/lib/mysql2/mysql2.so (LoadError)
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:4
5:in `require’
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2.rb
:8:in `’
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:1
10:in `require’
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:1
10:in `rescue in require’
from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:3
5:in `require’
from download.rb:6:in `’

到Mysql的安裝目錄,把libmysql.dll和libmysql.lib都拷貝到了Ruby的bin目錄下,再運行(程序裡用到了ActiveRecord),這次出了SegmentFault錯誤。。。。

3. 第二次安裝

網上查了查,應該是這個問題導致的。按照這篇文章的內容,依次如下處理。

另外,出現segment fault的根本原因應該是默認的libmysql.lib和mingw64-gcc不兼容導致的。

3.1. 卸載剛裝的Mysql2

> gem uninstall mysql2
Successfully uninstalled mysql2-0.3.13

3.2. 下載需要的工具

主要是gendef.exe,這個應用從https://structure-svm-map.googlecode.com/files/svm-map-win.zip下載

下載後從下面的文件夾找到這個文件,拷貝到devkit/mingw/bin下,我之所以考到這裡,是因為dlltool.exe也在這裡,都放到path裡方便。

然後運行:

gendef.exe libmysql.dll

這條命令會生成libmysql.def文件。

生成這個libmysql.def文件之後,就可以生成新的lib了。

dlltool -v –dllname libmysql.dll –def libmysql.def –output-lib libmysql.lib

3.3. 再次安裝mysql2

gem install mysql2 — ‘–with-mysql-lib=”C:\Program Files\MySQL\MySQL Server 5.6\lib” –with-mysql-include=”C:\Program Files\MySQL\MySQL Server 5.6\include”‘

3.4. 拷貝生成的libmysql.lib到ruby/bin文件夾

再次運行程序,OK。

Copyright © Linux教程網 All Rights Reserved