Nathaniel Ford
Nathaniel Ford

Reputation: 21239

LoadError trying to use MySQL with Ruby on Rails in Windows, RubyMine IDE

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!

Upvotes: 3

Views: 9536

Answers (4)

Salman
Salman

Reputation: 1

How to install ruby on rails on windows machine with mysql (wamp)

  1. install rails installer
  2. 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
    
  3. make sure that you have ruby installed for i386 not x64 bit, same goes for the wamp as well.

  4. 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"'
    
  5. Now, when you create your app, use the following command:

    rails new APPNAME -d mysql
    
  6. 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 the libmysql.dll and paste it into the bin folder of your ruby, in my case, it is C:\RailsInstaller\Ruby2.1.0\bin

I hope everything will work fine.

Upvotes: -1

meshr
meshr

Reputation: 31

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

Upvotes: 1

Ritesh Kumar
Ritesh Kumar

Reputation: 2223

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

Upvotes: 4

Anand Shah
Anand Shah

Reputation: 14913

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.

Upvotes: 22

Related Questions