Topic: Windows 7, RoR, and Mysql???

I'm a .net dev who wants to try out ruby on rails, but after 4 hours of trying to get it to work on Windows 7 with MySQL, I'm about to pull my hair out.   

The default "Welcom aboard" page comes up, but the picture doesn't and in the console I get:
"Mysql2::Error (Can't connect to MySQL server on 'localhost' (10061)):"

I've seen about a thousand guides/tutorials/posts/etc.. on why this happens and how to fix it, but nothing has worked.

Here is the process I've come up with:

    - Install Ruby
        - http://rubyinstaller.org/downloads/
    - Make sure gem is up to date
        - gem update --system
    - Install Rails
        - gem install rails
    - Install MySQL
        - http://www.mysql.com/downloads/mysql/
    - Install mysql gem
        - gem install mysql2
    - Install Ruby on windows dev kit
        - https://github.com/oneclick/rubyinstall … opment-Kit
        - Generate devkit config file
            - C:\RubyDevKit> ruby dk.rb init
        - Run dev kit install
            - C:\RubyDevKit> ruby dk.rb install
        - Test Installation
            Confirm your Ruby environment is correctly using the DevKit by running gem install rdiscount --platform=ruby. RDiscount should install correctly and you should see Temporarily enhancing PATH to include DevKit... in the screen messages. Next run ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html" to confirm that the rdiscount gem is working.
    - Fix MySQL connector DLL
        - http://www.mysql.com/downloads/connector/c/
            - download mysql-connector-c-noinstall-6.0.2 zip (32 bit version)
            - copy libmysql.dll from lib directory inside zip and paste it into ruby bin install location "C:\Ruby193\bin"
                        - compile mysql2 with my version of mysql connector
                             - gem install mysql2 --platform=ruby -- --with-mysql-dir=C:/RailsInstaller/mysql

Versions I'm using:
Win 7 64bit
Ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
Rails 3.2.6
MySql Ver 14.14 Distrib 5.5.25, for Win64 (x86)
mysql-connector-c-noinstall-6.0.2-win32
mysql2 (0.3.11 ruby x86-mingw32)
database.yml:
development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: root
  password:
  host: localhost

I can pull up a mysql prompt, login and see the databases.  So, I think MySql is working, there is just some connection issue where Rails can't talk to it.  Any ideas would be greatly appreciated.
Thanks

Last edited by TimB (2012-06-29 16:04:06)

Re: Windows 7, RoR, and Mysql???

Same Here. I tried  twice on two different computers. Always faced the same problem. I had some previous sql problem by running x64 db connector but reverted to 32 bits. Now I'm stuck on the same error as you. If I don't get this fixed tomorrow, I'll just drop the thing altogether and go to another language platform where at least I know I can solve the problems I run into.

Re: Windows 7, RoR, and Mysql???

First thing  - you had to install DevKit before installing mysql2 gem. In your workflow it comes after. May be that is the reason. I installled a lot of times RoR environment on XP, 7 (32 or 64 bites) without any problems.
Second point - I have never had to install mysql2 gem as you did:

- gem install mysql2 --platform=ruby -- --with-mysql-dir=C:/RailsInstaller/mysql

just Ruby -> DevKit-> mysql2 gem -> mysql dll copied in Ruby bin directory. And it always worked like a charm.
If you still have problems with that, post the stack trace errors at mysql2 GIT issues https://github.com/brianmario/mysql2/issues or at Ruby Installer google groups: https://groups.google.com/forum/?fromgr … installer. The guys from there are at ease to help you:)

Last edited by Javix (2012-07-22 16:18:40)

Re: Windows 7, RoR, and Mysql???

I'll try that first thing in the morning when I get to work. I'll unstall everything except mysql server and connector
then I'll follow the chain:

Ruby -> DevKit-> mysql2 gem -> mysql dll copied in Ruby bin directory

Now, just to be sure, is installing the environnment through railsinstaller.exe compatible with the chain order you mention or you don't recommend doing that?

Last edited by muichkine (2012-07-22 16:35:32)

Re: Windows 7, RoR, and Mysql???

I would guess that you are not using the correct address for the socket to connect to mysql.  Take a look at the mysql.conf to see what it is using and then specify that file location in the database.yml

Re: Windows 7, RoR, and Mysql???

OK, I reinstalled everything following the given order. I did start a rails sqllite projet which seemed to run fine. I created a mysql projet (rails new project -d mysql) and....same error once again and again.

I have no clue at all where rails get the idea of connecting to port 10061 for mysql. My root project's database.yml looks like this:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: root
  password: *********
  host: localhost
  port: 3306
  socket: /tmp/mysql.sock

The simple_cms_development db is existing. The password is my real root password which works when connecting to the db through mysql workbench. the socket is the one stated in the mysql_config.pl file.

Now, what else can one do?

Re: Windows 7, RoR, and Mysql???

OK, go the answer:

Adding (uncommenting)
127.0.0.1 localhost
C:\Windows\System32\drivers\etc\hosts
solved this.

Taken from:
https://github.com/brianmario/mysql2/issues/157

Re: Windows 7, RoR, and Mysql???

Personally, I've never used rails installer. What for? You already have everything you need: Ruby windows installer + DevKit. The rest is just to download mysql installer, install needed gems from the console, copy-paste mysql DLL where needed; That's all. Why to apply for any additional 3-party vendor,? - to have some unexplainable config errors like that?

Last edited by Javix (2012-07-23 11:17:32)

Re: Windows 7, RoR, and Mysql???

Wow... I had seriously given up on this.  I spent a week messing with it, then moved on to ASP.NET MVC.  Maybe I'll give this another shot, Thanks for the ideas.

Are there any other forums for Rails, or is this the most active one?

Re: Windows 7, RoR, and Mysql???

and that's another reason I want a different forum...  This one is REALLY bad about spam.