2

I am getting the following error

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 126: The specified module could not be found.   - C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError)

When trying to run this script...

require "mysql2"

client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "system32")
results = client.query("SELECT * FROM project1_nodes").each do |row|
  puts row
end

Any ideas?

Cheers Martin

marscom
  • 615
  • 2
  • 11
  • 24
  • 3
    Not an *exact* duplicate, but this solution should also solve your problem: http://stackoverflow.com/questions/4241068/rubymine-3-0-setup-on-windows-7 ((just adjust the windows paths to the correct paths, assuming you're not using windows). – Ben Lee Mar 30 '12 at 03:27
  • 1
    See also: http://stackoverflow.com/questions/4121524/problem-with-ruby-on-rails-installation-how-to-use-wamp-mysql-installation – Ben Lee Mar 30 '12 at 03:28
  • Sorted that one but now I am getting this error - C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 193: %1 is not a valid Win32 application. - C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError) - Any ideas? – marscom Mar 30 '12 at 03:53

2 Answers2

12

I guess you are running ROR on windows. So follow these steps.

  1. make sure you installed mysql correctlt.
  2. copy libmysql.dll(from mysql installation directory) file into you C:/Ruby193/bin folder
  3. now remove older mysql installed gems.
  4. reinstall mysql gem.

This might fix your problem.

Muhammad Sannan Khalid
  • 3,127
  • 1
  • 22
  • 36
  • 3
    I am running Ruby, no rails. I have tried this but I am getting still the error - C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 193: %1 is not a valid Win32 application. - C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError) - Any ideas? – marscom Apr 05 '12 at 07:18
  • This answer did sort the original problem, though I still have an issue with the new error message, I have opened up a seperate question for it. Thanks – marscom Apr 05 '12 at 07:23
  • [installing-mysql-on-windows-7-x64-and-using-ruby-with-it](http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/) explains the problem and solution in more detail... though this is for mysql gem, it also worked for mysql2. – Zeeshan Aug 05 '12 at 20:20
0

If you're using RVM, are you using a specific gemset?

I've had similar issues and setting specifying a specific gemset has fixed my issues. For example, I'll installed a gem, but then won't be able to load it with a require 'example_gem_name' call. This fixed my issues,

rvm gemset use gemset_name  
gem install mysql2  
gem list mysql2  

Also, to set the RVM default gemset (so you don't have to every time),

rvm use 1.9.3@gemset_name --default
westonplatter
  • 1,475
  • 2
  • 19
  • 30