0

I'm running Rails 4.0.3 on Ruby 2.0.0 on Windows 7, and have installed the DevKit (all x64). I've installed the mysql2 gem using subst X: "C:\Program Files\MySQL\MySQL Server 5.6" and then gem install mysql2 --platform=ruby -- --with-mysql-dir=X:, and it installed fine. I then created a new app with rails new mysql_testy which ran fine, but when I run rails server I get the following error:

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2.rb:8:in 'require': 193: %1 is not a valid Win32 application.   - C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2/mysql2.so (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2.rb:8:in '<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in 'block (2 levels) in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in 'each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in 'block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in 'each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler.rb:131:in 'require'
from C:/Users/Liam/Ruby/mysql_testy/config/application.rb:7:in '<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in 'require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:74:in 'block in <top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in 'tap'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.3/lib/rails/commands.rb:71:in '<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'`

Do you guys have any idea what's happening?

Liam Baker
  • 103
  • 7
  • The answer to this question should solve your problem: http://stackoverflow.com/questions/10468118/193-1-is-not-a-valid-win32-application-error-with-ruby-1-9-3-on-rails3-2-3 – rails4guides.com Mar 11 '14 at 16:41
  • @rails4guides.com: In that question, the asker had installed a precompiled binary version of the mysql2 gem, whereas here it was installed using DevKit to build native extensions for my system. Also, when I tried using Ruby 1.9.3 as per the guides I found on the web (like the first answer to the question you linked to) I did not even get as far as correctly installing mysql2. – Liam Baker Mar 13 '14 at 11:45
  • It seems the problem is that Ruby is Win32 and your MySql is Win64, which results in raising an incompatibility error. This article might solve your problem: http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/ – rails4guides.com Mar 13 '14 at 12:09
  • Are you sure my Ruby is Win32? I explicitly installed the x64 version of Ruby... – Liam Baker Mar 13 '14 at 14:25

1 Answers1

0

Not sure if you figured it out yet, but I was having the same issue. I installed the 32 bit sql connector, copied the libmysql.dll file from it and pasted it into Ruby/bin folder. Opened a new command prompt and was able to connect to the server.

Before this step though you may have to reinstall a fresh MySQL2 gem pointing to the path of the connector: gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\mysql-connector-c-6.1.5-win32\lib" --with-mysql-include="C:\mysql-connector\mysql-connector-c-6.1.5-win32\include" --with-mysql-dir="C:\mysql-connector"'

Hope this helps

ProGM
  • 6,949
  • 4
  • 33
  • 52
NA Peters
  • 259
  • 4
  • 15