问题
I am getting the following error when trying to run a simple Ruby on Rails application from RubyMine:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': 126: The specified module could not be found.
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError)
The thing is, that file is actually there. Further, I've run 'bundle install', associated the mysql with the project, and everything else I can find. There is some suggestion on the net that libmysql.dll needs to be in a particular directory - but no indication to get that particular file.
Does anyone know how to fix this problem? Thanks!
回答1:
I fixed a similar error by copying libmysql.dll to the "bin" directory. In your case copy libmysql.dll to C:\Ruby192\bin
libmysql.dll gets installed when you intall MySql. The location of the file depends on whether you are using WAMP, XAMPP or just MySql. If you can't locate it search for it on your computer, ofcourse I assume here that you have MySql installed and that its running.
回答2:
Thanks, I was able to fix the error. To fix this error, I copied "libmySQL.dll" file from 'C:\Program Files\MySQL\MySQL Server 5.1\bin' to 'C:\Ruby192\bin'. For details, refer to post - http://rorguide.blogspot.com/2011/03/getting-error-specified-module-could.html
回答3:
I copied libmysql.dll
from mysql-connector-c-6.1.5-win32.zip\mysql-connector-c-6.1.5-win32\lib
from here http://dev.mysql.com/downloads/connector/c/ to ruby bin directory to make it working
回答4:
How to install ruby on rails on windows machine with mysql (wamp)
- install rails installer
solve the https certificate issue by using these commands (source)
ruby "C:\RailsInstaller\win_fetch_cacerts.rb" set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem
make sure that you have ruby installed for i386 not x64 bit, same goes for the wamp as well.
install the gem locating the mysql lib file
gem install mysql2 -- '--with-mysql-lib="C:\wamp\bin\mysql\mysql5.6.17\lib" --with-mysql-include="C:\wamp\bin\mysql\mysql5.6.17\include"'
Now, when you create your app, use the following command:
rails new APPNAME -d mysql
When you will try to instantiate the server by using the command rails server, it will give you tonnes of mysql errors, but don't worry there is one more step which can solve it:
go to the lib directory of mysql:C:\wamp\bin\mysql\mysql5.6.17\lib
copy thelibmysql.dll
and paste it into the bin folder of your ruby, in my case, it isC:\RailsInstaller\Ruby2.1.0\bin
I hope everything will work fine.
来源:https://stackoverflow.com/questions/5164818/loaderror-trying-to-use-mysql-with-ruby-on-rails-in-windows-rubymine-ide