rake aborted: no such file to load mysql

Programmers who work mostly on windows have seen this kind of errors many times.. as a windows programmer I have been through many sites and collect d relevant data, now I am showing it to you..

The errors which might come to you something like this:
no such file to load mysql
rake aborted: no such file to load mysql
The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql
Could not find RubyGem rake-compiler (~> 0.5)

To solve such problems follow these steps:
Step 1. Update rubygems to the latest version(like I upgraded it to 1.3.5).
Step 2: install rake-compiler(by gem install rake-compiler).
Step 3: if already installed hoe gem update it(gem update hoe) or install a fresh one.
Step 4: Download libMySQL.dll from here and copy it into C:/ruby/bin or wherever your ruby is installed, but make sure it should be in bin directory.
Step 5: Stop the mysql service, from Control Panel -> Administrative tools -> services -> mysql, and then restart it.

That’s it. You are done, after all these steps you can try
rake db:migrate
Suppose if that doesn’t work then after 4th step, stop the mysql service and restart your system.

I welcome all of you to post your comments, feedbacks, queries

Cheers!!
Puneet Pandey

Advertisements

21 thoughts on “rake aborted: no such file to load mysql

  1. adl

    hi
    i did what you say i am reciving this message when i do rake db:migrate
    how can i fix this
    rake aborted!
    no such file to load –sqlite3
    see full trace by runing task with –trace

    each time i try to run my application i recive the avove mesge then when i ignore it i put ruby script/server
    i open just hte first page then errors

  2. All you need to do is to install sqlite3 gem by typing:
    gem install sqlite3 in command prompt. and you are getting this error coz your application has sqlite3 settings stored in config/database.yml

    If you want to use mysql then make sure whenever you are creating new applications it should have mysql database like:
    rails my_app –database=mysql

    In Your case all you need to do is to change the database.yml file like this:
    development:
    adapter: mysql
    encoding: utf8
    reconnect: false
    database: your_database_name
    pool: 5
    username: root
    password: your_mysql_pwd

    save it and restart your server. It should run, if you have mysql installed and its gem ‘mysql’

    Let me know if it works

    Cheers
    Puneet Pandey

    1. adl

      Hi

      thank you so much

      but still not working when i put gem install sqlite3 recive message says:
      ruby.exe:no such file to load –ubygems

      i tried in my other computer also recive diffrent message says:
      ERROR: could not find gem sqlite3 locally or in a repository.

      also i want to aske you about these steps cuz i have my sql in one of my computer:
      development:
      adapter: mysql
      encoding: utf8
      reconnect: false
      database: your_database_name
      pool: 5
      username: root
      password: your_mysql_pwd

      do not know where i supose to go to put these
      iam beginer in ruby in rails

      thank you

  3. I suggest you to download and read some pdf’s on ruby on rails.. your approach is wrong.. you’ve started programming directly which is wrong.. there are online tutorials, books which has some demo rails application.. google it and try it, It will guide you through all the steps…

  4. Ganesh Kathare

    Hi Puneet,

    I need help for following Mysql problem :

    \>> @slugs = Slug.all

    ActiveRecord::StatementInvalid: Mysql::Error: MySQL server has gone away: SELECT * FROM `slugs` from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:595:in `select’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:615:in `find’ from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:635:in `all’ from (irb):6

    I don’t know how to resolve this problem.. !

    Basically facing this problem while I’m working on the ruby Console of myproject.

    After this error each time I have to reload console then only I can proceed further work..

    Not getting exactly why?

    I’m using Ruby 1.8.6, Rails – 2.3.2

    Thanks in advance..!
    🙂 🙂

  5. Ganesh Kathare

    Problem is :

    “Mysql::Error: MySQL server has gone away: ”

    getting this error only on ruby console..

    Any solution..?

    Thanks..!

  6. Sounds like a strange error to me…. I’ve never faced it before.. if you can provide me some more inputs about what exactly you’re trying to do.. may be we’ll be come up with some solution.\

    Cheers!
    Puneet

    1. Ganesh Kathare

      Hi Puneet,

      Thanks for ur reply..

      But I have resolved this issue..!

      I didnt find source(i.e origin) of this issue.. I think It might be due to some rails caching problem..

      After many trial I gone with following solution..

      module ActiveRecord::ConnectionAdapters
      class MysqlAdapter
      alias_method :execute_without_retry, :execute

      def execute(*args)
      execute_without_retry(*args)
      rescue ActiveRecord::StatementInvalid => e
      if e.message =~ /server has gone away/i
      warn “Server timed out, retrying”
      reconnect!
      retry
      else
      raise e
      end
      end
      end
      end

      The above code is being used in rails configurations files..
      Issue has been actually resolved by using MysqlAdapter’s exception notifications..!

      Thanks,
      Ganesh Kathare.
      (ROR-Developer) 🙂

  7. Pravin Parulekar

    If this mysql dll is so much essential, why is it not bundled with the gem?
    Thanks so much, my proble was solved after I kept this dll in the bin directory!!!

    1. They have not configured this gem or I can say updated this gem(for windows).. so we have to do this manually.. but for most of the users, this must not be required.. for few cases we can follow 🙂

      Cheers!!
      Puneet

  8. Hey I have noticed that you have given explanation for windows programmer. I am wondering whether I should use the same solution on ubuntu or there is another solution because I am facing the same problem when I issue command rake db:migrate.

    1. I think you should give a try… but ignore the steps for mysql.dll file… I think its no more in use when you are dealing with Linux Environment and then let me know what are you getting..

      Cheers!!

  9. Sandino

    Thanks a lot for this solution.
    I tried with the same file wich come along with xampp in xampp/mysql and it did not work…this one made the trick!!!
    thanks again for sharing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s