TechSoft Solutions

Web and Database Development, General Tech tips and Tricks and TechLabs TV IT Training services.

This is a simple workaround regarding an error which happened to me today when running db migration in Rails 3. I have Rails 3.2.2 and MySQL 0.3.11. I was trying to run

bundle exec rake db:migrate

to create a table in database. I got this error

rake aborted!
Can't connect to MySQL server on 'localhost' (10061)
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

My simple work around was going to config/database.yml file and changing the host to use 127.0.0.1 instead of localhost as follows.

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: quiz_development
  pool: 5
  username: root
  password:
  host: 127.0.0.1

About Samuel K Itotia

IT Project Consultant, Bachelor of Computer Science holder, Microsoft Certified IT Professional. Certified Google Apps Cloud Deployment specialist and Trainer. Passionate on the new trends of Technology. He will always share it with the world.

20 Responses so far.

  1. Hi Samuel,

    Changing localhost to port number worked for we as well. But I am bit surprised here that localhost has also/run on the same port, then why I had to define the IP Address instead of localhost.

    - Puneet

    • Samuel K Itotia says:

      Punnet,
      I am not quite sure why the case but out of trial and error I manage to solve the error. I ll investigate on the issue and post on the same. Thats a good note.
      Thanks
      Samuel

  2. Ed says:

    Worked for me as well. Thanks.

    Why does this work?

  3. Werther says:

    Man, u save my life. :)
    I was trying a lot of things, but not thinking in do that (127.0.0.1). The mysql workbench uses localhost, other applications also uses localhost. I tried to use localhost, LAN IP, LAN dns name and nothing had worked.
    Well, now is working fine. Thank u a lot.

  4. Matt says:

    WOW! Just learning Rails, mySQL. Always “Can’t connect to mySQL…” thought I would never connect and get past this point. This worked. After 8 hours stuck,I have a long way to go but I am on my way again! Thanks.

  5. Hackman says:

    thanks alot . it worked for me

  6. Brian says:

    Brilliant. Another satisfied customer here.

  7. Khushboo says:

    Man, I spent a lot of time on this … but nothing worked !

    Your trick worked so well… thanks :)

  8. yeheyuan says:

    Thanks a lot. I was stucked whith this error and U saved my life :-D

  9. elvis says:

    Hello guys, please am trying to create a table using
    db:migrate
    but i keep getting this error message
    !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
    rake aborted!
    126: The specified module could not be found. – C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so
    #tho the file mysql_api.so exist there
    Tasks: TOP => db:migrate
    (See full trace by running task with –trace)
    Please what can i do

  10. vidur says:

    Thanks it helped.

  11. mamsoares says:

    Fantastic. It worked for me.

    Thanks a lot.

  12. It worked for me says:

    It worked for me :)

  13. Kushal says:

    Thanks a lot:)

  14. Konstantin says:

    You can add next row at file C:\Windows\System32\drivers\etc\hosts:

    # localhost name resolution is handled within DNS itself.
    127.0.0.1 localhost

    In this case you should change ‘localhost’ alias to direct ip address

  15. hapm says:

    Worked for me as well, but i would be interested in why it works o0. Is it possible that this is related to localhost being resolved as ::1: on newer machines with IPv6 enabled? Only an idea, blame me if i’m totally wrong here.

  16. Crhistian says:

    thank you very much!

  17. zadu says:

    if this type problem exist then open task manager and go to services and start my sql
    services.


  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Popular Posts

Can't connect to MyS

This is a simple workaround regarding an error which happened ...

Apache Port 80 colli

Most people that are new to Apache spend most time ...

Building clusters wi

Clustering in Windows Server 2008 has been radically redesigned to simplify ...

What is Rhomobile an

Rhomobile is an open-source Ruby-based mobile development framework for business ...

Sponsors

  • Cheap reliable web hosting from WebHostingHub.com.
  • Domain name search and availability check by PCNames.com.
  • Website and logo design contests at DesignContest.net.
  • Reviews of the best cheap web hosting providers at WebHostingRating.com.