Having issues attaching ruby to mysql using the mysql2 gem - mysql

Rails version 6.0.4.6
Ruby Version 2.7.5p203
mySql version 8
OS Window 10
I am having issues getting the mysql2 gem to work. The latest error I have is not being able to locate "mysql2 x64-mingw32" file. I installed the gem using this command:
gem install mysql2 --platform=ruby -- --with-mysql-dir="C:\Program Files\MySQL\Connector C++ 8.0"
--with_mysql-lib="C:\Program Files\MySQL\Connector C++ 8.0\lib64" --with_mysql_include="C:\Program Files\MySQL\Connector C++ 8.0\include"
It appears to have been installed correctly but still will not work. I have run bundle install. I have also tried deleting the gem.lock file and the running bundle install.
If anyone has had success in getting ruby to work with MySQL on a Windows machine, please let me know how you did it.

After many trails, it appears the Ruby just doesn't play well with Windows OS. While I expect that some do use Ruby on Windows, it appears the support is lacking, and the community is small.
I installed a Linux terminal on my machine and had much better luck.
Just posting to keep other from pulling their hair out.

Related

Rails - Error installing Gem

Im newbie starting to learn ruby/rails. While i was trying to setup WeBRICK to run, an error related to the libmysql.dll appeared, so ive downloaded an dll from an older version of mysql and tried again, but the error kept. Then i read that the problem was that my computer is 64bit and the gem mysql2 installed apparently is 32bit, that way i uninstalled that gem and tried to do the following workaround:
1) download mysql connector 32 bits
2) gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32
the problem now is that im getting the following error:
ERROR: While executing gem ... (Errno::EEXIST)
File exists - C:
So, now i cant even install the mysql2 gem
Can you guys help me please?
It's not recommended to run ruby on rails on windows. mac or linux will be better.
if you can't change your OS. you can try this:
http://eric.cloud-mes.com/2012/04/1/install-Ruby-1.9.3-and-Rails-3.2.3-on-Windows-7.html

193: %1 is not a valid Win32 application error with Ruby (1.9.3) on Rails(3.2.3) with MySQL(5.5) on Windows 7

I cannot seem to run a rail application configured to MySQL. When I run the project, I get the following error:
193: %1 is not a valid Win32 application. - C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so
I've noticed others have hit this but I didn't find any solutions that worked for me. Here's what I've tried so far:
Copying libmysql.dll to the ruby bin folder
Tried older version of MySQL (5.0)
Checked the ImagePath for MySQL on regedit
Can anyone provide guidance here? Is this just a lost cause? Does using Linux or other versions of Ruby/Rails/MySQL combo fix this?
Looks that you installed the binary pre-compiled version of MySQL gem, which requires an specific version of MySQL to be installed.
More important, it requires an specific version of libmysql.dll be available in the PATH so the gem can use it.
I would recommend you uninstall the pre-compiled gem and proceed with the manual compilation steps described here:
http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
This has been answered before too:
Ruby Gem for mysql 5.5 in windows
Is Datamapper's dm_mysql_adapter gem supported on windows?
Finally installed MySQL for Rails in Windows 64 bit, and now
on windows Mysql native extension prob in ruby on rails gem time
Hope that helps.

How to install Ruby on Rails with mysql and get it working, a step by step guide?

Some time ago I managed to get RoR working on Windows XP.
I've been trying to get it working on Windows 7 for 2 days but there's just no way, there's always a problem, one that google can't answer, no matter what I try.
Can someone give me a guide or something to get it working on Windows 7 or XP ? Even Ubuntu but I'd rather not go through that maze again.
I figure I'm going to install Windows XP on a virtual machine and start from there.
I need RoR and mysql - what versions, where do I download them from and what steps do I take ?
On a side note, how do you install mysql2 (version < 0.3) on rails 3.0.7 ? Because it automatically tries something over 0.3 which doesn't work on rails 3.0.7 and if I try the gemfile bundle trick with 0.2.7 I don't know how to specify configuration options and of course it doesn't work if I don't give it the location of mysql lib and include directories.
Also I tried using rails 3.1 beta and everything goes smoothly until I start the server and the website never loads on localhost:3000.
This is basically what I do to install on Windows 7:
Download and install latest mysql from http://dev.mysql.com/downloads/mysql/
Install Ruby http://rubyinstaller.org/downloads/ (check the box to update PATH)
Install Ruby Devkit http://rubyinstaller.org/downloads/ (for example extract to C:\DevKit)
Setup Devkit
cd [MY_DEVKIT_INSTALL_DIR]
ruby dk.rb init
ruby dk.rb install
Copy libmysql.dll from your mysql/bin install to C:\Ruby192\bin
gem install rails
gem install mysql2 -v 0.2.6
rails new my_test_app -d mysql
To setup Rails on windows, just download and click:
http://railsinstaller.org/
Take a look at http://rubyinstaller.org/ it should get you up and running.
I like Aptana Studio 3 for developping with RoR on Windows 7. The book "Agile Web Development with Rails" is also full of good advices.
Here are the steps I followed:
1- Installing Ruby via RubyInstaller
2- Install MySQL (follow #Reuben Mallaby instructions)
3- Install Rails
With the Built-in Terminal, make dev' easy. You should take a look: Aptana Studio

Installing Rails, MySQL, etc. everything goes wrong

I've been struggling with this for a few hours. Everything just stopped working and I can't get it to work anymore. I'm a noob at Ruby, Ruby on Rails and the Terminal in general. This is really frustrating me so I just try to describe my problem as detailed as possible hoping someone can give me a solution.
I'm on Mac OS X Snow Leopard. I couldn't get Rails working at all just now: Could not find gem 'rails' headaches
But after some tries of reinstalling it, it suddenly worked again. But now I just can't get MySQL to work, and it sometimes even breaks the Rails installation again.
This is what I do:
sudo gem uninstall rails
sudo gem uninstall mysql
sudo gem uninstall mysql2
After these commands, I check the installed gems with gem list. No MySQL gem is listed anymore, but I can still see rails (2.3.5, 2.2.2, 1.2.6)
. Is this normal? Does this mean I have 3 Rails installations? It doesn't make sense to me. Anyway, then I do this:
sudo gem clean
Which fails completely. I get a bunch of errors like this:
Attempting to uninstall fcgi-0.8.7
Unable to uninstall fcgi-0.8.7:
Gem::InstallError: cannot uninstall, check gem list -d fcgi
It doesn't uninstall anything. At this point, I try to install everything again. I start with:
sudo gem install rails
Which succeeds (I think):
Successfully installed rails-3.0.3
Successfully installed builder-2.1.2
2 gems installed
Installing ri documentation for rails-3.0.3...
File not found: lib
Then, I update RubyGems:
sudo gem update --system
sudo gem install rubygems-update
sudo update_rubygems
Then it says I have 1.3.7 installed, so it succeeded, I think. So now I proceed with installing MySQL. I already got MySQL 5.5.8 installed on my machine. I did some research about installing MySQL on Snow Leopard, and it seems I have to use this command:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I get a bunch of errors like this:
No definition for time_set_neg
No definition for time_set_second_part
No definition for time_equal
No definition for error_errno
At this point, I assume I got both Rails and the MySQL gem installed, so I try to start a new project.
rails new user_group -d mysql
It works! Rails is installed correctly. Now, I try generating a model.
cd user_group
rails generate model User
It fails with this error:
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
Try running bundle install.
So I try running bundle install. It installs a lot of gems. Then I try to generate my model again. I get this error:
Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
This is as far as I can get. What should I do? And why should this be so hard...
Snow Leopard supplies Ruby 1.8.7. Ruby 1.8.7 doesn't automatically add the require 'rubygems' command to a Ruby script, like 1.9.2 will, so in general you need to add that to your script. That fixes the problems with Ruby not finding the gems called by your code in a lot of cases. Rails is a different animal, but the version with 1.8.7 is well documented so you should have found a fix pretty quickly.
The Ruby supplied by Snow Leopard is really for its own use. Users can piggyback on that, but it's installed by Apple because they have applications that use it. Use locate podcast | grep rb$ to see. Similarly, Perl and Python in Snow Leopard are used to support code Apple has installed so messing with them is not a good idea. Changing the built-in Ruby, Perl or Python usually won't cause the system to explode in flames, but it can cause irritating and unexplained problems farther down the road when system maintenance routines stop working.
By using sudo to remove gems installed by Apple and add new ones, you've left your system Ruby in an unexpected state as far as Apple's apps are concerned. Rather than mess with Apple's Ruby, you should install a separate Ruby for your own use using Fink or MacPorts, or from source code, or by using RVM.
Personally, I use RVM because it creates a ~/.rvm sandbox in your home directory, and makes it easy to manage multiple versions of Ruby and gems. RVM requires you to install the XCode development library, which you can download from http://developer.apple.com/technologies/ after a free registration. XCode is also on your system DVD, but that version is reported to be buggy, so use the downloaded version.
Make sure to add the MySql gem to that projects gemfile with the following code:
gem 'mysql', '2.8.1'
Run a bundle install/update and try it. You told it to use MySQL and the gem might even be installed, but you aren't loading it.
Also, you're failing at a couple of points: notice the
File not found: lib
Then again, I could be completely wrong about this - it's my attempt at providing a clue for your troubleshooting.

Setting up Mysql for Ruby on Rails in Windows

I'm on Windows, and I have a working Rails 2.3.8 app on Ruby 1.8.6 with MySQL 5.0 and the mysql gem version 2.8.1. It all works.
I just installed Ruby 1.9.1, installed gems for rails(2.3.8) and mysql. BUT NOW when I run ruby script/server:
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
I ALREADY INSTALLED IT!
One thing that might be a problem:
When I run "gem list" in my working ruby (v1.8.6) install, it lists "mysql (2.8.1)". BUT when I run "gem list" in the new ruby install (v1.9.1), it lists "mysql (2.8.1 x86-mingw32)". If that's the cause, how do I fix it? If it's not, what on earth is keeping Rails from recognizing the installed mysql gem?
Thanks in advance. I'm sure this is a common upgrade path, so I can't be the only one with this problem...
Finally got some solid info.
Apparently the mysql gem sucks, and shouldn't be relied on going forward.
That's why Rails 3.0.0 officially endorses the mysql2 gem instead (gem install mysql2), which unfortunately is not supported under Windows yet, though the gem's developer seems to be working on it.
As I try to get my app to Rails 3, I'm just going to make the easy switch to sqlite3 until there's a good mysql gem for windows.