Rails Server not Working (LoadErrror mysql2) Windows - ruby-on-rails

I am trying to run rails server command but it showing mysql2 Load Error. I will place my Error log here
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!

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"

im not using windows. but seems to be duplicate with posts like this (Error "...cannot load such file -- mysql2/2.0/mysql2 (LoadError)". On Windows XP with Ruby 2.0.0)

Related

windows 10 ruby2.5 rails 5.1.5 cannot load such file -- sqlite3/sqlite3_native (LoadError)

environment:
windows 10 ruby2.5 rails 5.1.5
problem:
cannot load such file -- sqlite3/sqlite3_native (LoadError)
I have try gem uninstall sqlite3 and gem install sqlite3 ,any solution on web has been try ,not working,anyone could help me? I need to fix this problem,my work need to move on. Thanks.
I resolved the problem similar to you. This does work when I require sqlite3 in Ruby. However, when used in Rails, the bundler will install the native version, which doesn't work. I have to run bundle update, uninstall the native version with gem uninstall, and then edit the sqlite3 entry in the Gemfile.lock to sqlite3 (1.3.11) or (1.3.13) and now it's working.
Or sometimes it's depending on many other reasons when we search to the Google with writing same error then it's showing the huge result every other person solved this differently. So if you not resolving this with my style then you need to research and need to try every possible way.
I encountered the same problem while using Windows 10. I installed rubyinstaller-devkit-2.5.1 which I uninstalled. I downloaded rails from railsinstaller.org. It works perfectly for me. I searched almost everywhere, none of the solutions were helpful
The sqlite3 gem isn't updated for Ruby-2.5, yet, but there's a simple workaround for using sqlite on RubyInstaller-2.5. Add this to your Gemfile:
gem 'sqlite3', git: "https://github.com/sparklemotion/sqlite3-ruby"
and run bundle install.
See also the RubyInstaller FAQ.
I had this same problem, spent hours searching but none of the solutions worked for me and all everyone said was used rails installer but I already had everything installed and wasn't ready to move things around. I found a solution however it's really wonky. you have to run this almost everytime you restart your rails server.
gem uninstall sqlite3 --all
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem inst sqlite3 --platform ruby
I have also downloaded and placed the appropriate .dll and .exe files for sqlite3 from their homepage and in the ruby bin directory and added it to the windows PATH.

Rails: 'require': cannot load such file -- mysql2/2.2/mysql2 (LoadError)

I am new to rails and I have installed Ruby 2.2.2, Rails 4.2.3, Gem version 2.4.8, DevKit, a MySQL server, and it says that I have successfully installed the MySQL2 gem, however, when I go to the root directory of my web app and use the rails server command, I get the following error:
I reinstalled all of the programs (Ruby, Rails, MySQL2, DevKit, etc.) and I am still prompted with this error.
(P.S. I know that other people have posted this same problem but I couldn't find a solution that worked)
Thanks.

Rails project using MySQL gem not starting up on Windows 8

My specs are as follow:
Windows 8 64-bit
Ruby 1.9.3
Rails 3.2.12
I installed rails via the RailsInstaller. I have also installed the mysql2 gem. I created a new project that is pre-configured to use mysql e.g.
rails new project_name -d mysql
I then tried to start up the server/WEBrick via
rails server
And I get the following error:
I've tried this using the mysql2 as well as teh mysql gem. Both times I get the same error. When I use the default sqlite then the project starts up fine and I can view it on localhost:3000.
I'm aware that mysql2 used to be a problem on rails, but since mysql isn't working either I'm of the opinion that it's a Windows 8 specific project, surprise surprise.
I'd deff like to use MySQL rather than SQLite. Thanks for anyone that can point me in the right direction!
As a noted error case,
The SO Post says-
"The problem is with mysql. It is a 64 bit installation. Change it to 32bit and it runs fine."
Apart from that, this error may also be the result of some missing gems.
You should try running bundle install before running your server.
Also make sure that gem mysql is added to your gemfile before you do bundle install.
Please update your MySQL to 64bit version. It will fix the problem. Don't forgot to install the Devkit.

How to use "mysql2" gem in Rails 3 application on Windows 7?

I try to install the mysql2 gem on Windows 7 32-bit.
I run:
gem install mysql2
and I get the following error:
ERROR: Error installing mysql2:
The 'mysql2' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
Any ideas what could cause this error, and how to solve this ?
UPDATE
I did everything as described here, but I can't figure out the last step:
gem install mysql2 --
'--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.1\lib\opt"
--with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.1\include"'
I understand that I should change the paths to the correct paths in my system, but I can't find the lib\opt and the include directories in my WAMP MySQL installation. I use WAMP 2.1.
Please advise.
Here is a proper solution for anyone interested, that doesn't mess up your current installation of mysql server -
EDIT : Make sure you download the right version on MySQL server. :
if you intend to connect to a 6.0 or 5.5 server - download those binaries. I'm connecting to mysql 5.1 - hence my example. Also keep in mind latest mysql2 gem ( v 0.3.7) was tested against mysql server 6 - hence it keeps failing to build on windows for earlier versions. also make sure you use the right libmysql.dll in your ruby folder.
Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (From here)
Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.
Extract all the files from the zip file into the folder you just created.
now run this command
gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'
I just installed mysql2 gem v. 0.3.7
EDIT 1
One more thing: make sure you run the command in Command Prompt directly. As in not PowerShell or Consol2 - for some reason if you try that it will give you and error " invalid option" - has to do with the way -- is parsed.
EDIT 2
I just was doing a blank windows 7 install and one thing I ran into is that you need to add one more step to this: check to see if there is libmysql.dll in your ruby bin directory, if not copy one over from your mysql install. It should be of the same version as your mysql2 build.
THANK YOU! One note: I had to include the --platform=ruby option as well. Thus, the final entire command line was:
gem install mysql2 --platform=ruby -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'
When I tried it without the platform=ruby option, DevKit didn't run and it just installed the normal mysql2 gem - it even gave a warning message about mysql2 being built for 6.0.2. I uninstalled it (gem uninstall mysql2), then ran it again with --platform=ruby and it worked awesome!
Me: Windows 7 64bit, Ruby 1.9.3p125, Rails 3.2.1, MySQL 5.1.56
Well, i don't really use Windows, but what about downloading the DevKit from 'http://rubyinstaller.org/downloads' and following the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit' ?
Try XAMPP from apachefriends.org, be sure to download the full version and you will find "lib", "bin", "include" and other MySQL directories. For further details, refer to -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
You should execute the setup file again,and choose the modify option,then check the Developer Components.When it finish,you will found the include folder and the opt folder.
Not all mysql2 versions come with windows binaries.
Easiest way to install gem mysql2 on windows is to pick a version that includes win binaries.
Link to list of versions
Choose the latest version number that includes “x86-mingw32”
For example 0.3.11
To install it:
gem install mysql2 -v 0.3.11
or in the gemfile:
gem „mysql2“, „0.3.11“

LoadError when using heroku db:push

When i use "heroku db:push" to transfer my local data to heroku,i got this error message:
Sequel::AdapterNotFound -> LoadError: no such file to load -- sequel/adapters/mysql2
I already install the mysql2 gem, and i am using rvm with ruby 1.9.2 in Mac OS X Snow Leopard.
Are you using the most current version of Sequel? mysql2 support wasn't added until 3.15.0.
I'm able to use the original "mysql" gem still with rails3 instead of "mysql2" to get around this problem.
Taps is still not compatible with sequel 3.15 which has mysql2 support. So mysql2 adapter won't work heroku db:pull or db:push commands. But I got it working by using the old mysql adapter. i was facing problems because my mysql adapter wasn't configured properly. If you are on 64 bit macOSX. Try uninstalling mysql adapter and reinstalling it using:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Hope it helps.
might be old news, but make sure you are a) in the projects root folder and b) in the correct rvm gemset!

Resources