Search code examples
ruby-on-railsrubyrubygemsbundlemysql2

Rails Server not Working (LoadErrror mysql2) Windows


I am trying to run rails server command but it showing mysql2 Load Error. I will place my Error log here Error Log

I searched many places. I tried to install from my bundle itself using "gem install mysql2 --ruby=platform" command using connector c "libmysql.dll" file pasted in ruby/bin but no use.

I actually have MySQL installed on my system long back when I was doing JDBC connections. Its SQL server version 5.0- Is that version causing this error? Or Do I need to uninstall the MySQL from my system and install Latest Version! And a doubt for me is how is this MySQL Server 5.0 connected to Rails as I no I have no idea about it, because while installation I used Connector C 6.1 for mysql2 installation from the Command Promt!

I tried Ruby on Rails - cannot load such file -- mysql2/2.2/mysql2 (LoadError)

I also tried Error "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)". On Windows XP with Ruby 2.0.0 But I am getting the same error.

I think I have given all the details regarding versions and what I did! I tried doing this like 50 times but no progress! I hope I will get my problem solved !Thank You!


Solution

  • The following below instructions can help you.

    gem uninstall mysql2
    

    Download last MySQL connector from http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip

    Extract it to C:\connector-6.0.2

    gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\connector-
    6.0.2\lib" --with-mysql-include="C:\connector-6.0.2\include" --with-mysql-
    dir="C:\connector-6.0.2"'
    

    Or even shorter:

    gem install mysql2 --platform=ruby -- --with-opt-dir="C:\connector-6.0.2"