ruby on rails + xampp + mysql (windows 7) - mysql

I am trying to use the mysql package included in xampp with ruby on rails on windows 7, but cannot seem to get them to work together.
I have rails 3.0.0 and xampp 1.7.3
rails works with sqlite within xampp just fine, but when attempting to use mysql via "rails new project -d mysql; cd project; bundle install"
I get the following:
Installing mysql2 (0.2.4) with native extensions C:/xampp/Ruby192/lib/ruby/1.9.1
/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Fail
ed to build gem native extension. (Gem::Installer::ExtensionBuildError)
C:/xampp/Ruby192/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Am I missing anything? All the posts about this issue tell me to use gem install mysql -- --with-mysql-config=PATH, but this does not seem to work with Windows, as I get the same error regardless.
And if it's just not possible, are there any drawbacks to using sqlite now, then trying to migrate the databse over to mysql (or another more robust database) later?

Did you install the mysql gem?
gem install mysql
After this you need to go to the mysql\bin directory in your XAMPP folder and copy the
libmysql.dll
into your ruby\bin folder.
Give it a try and let me know if it works. Also if your MySql version is 5.1 you may need to download a 5.0 version of the same dll.

gem install mysql --no-rdoc --no-ri -- '--with-mysql-lib="D:\xampp\mysql\lib" --with-mysql-include="D:\xampp\mysql\include"'
I used this code for my solution of mysql this is the right way you can USE mysql for xampp.

I once had a similar issue. The important things i noted was that i already have mysql installed for usage via xampp. Firstly, you should make sure that the mysql installation is accessible from cmd by typing
mysql --version
If it gives you a reply of our installation then you're good to go to the next step else copy the mysql bin directory and save it in your user environment variable called PATH. This should allow you to run the cmd code above fruitfully.
Next Step: run (on cmd)
gem install mysql2 --no-rdoc --no-ri
This worked for me.

Related

Library not loaded: libssl.1.1.dylib (LoadError) when trying to run rails server and connect to mysql

Recently I updated my MacOS to Monterey 12.3 which included updates for xcode.
After that I am not able to run the rails application that I have been working on. I keep getting this error when I try to spin up the server.
I have tried installing and removing mysql different ways. Both using a brew install and DMG file from mysql website.
I am able to access the database instance through my command line but I think they issue is that it I can't connect from application. Anyone else having similar issues?
here is the full error
/Users/gus/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.6/lib/active_support/dependencies.rb:324:in `require': dlopen(/Users/gus/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): Library not loaded: libssl.1.1.dylib (LoadError)
Referenced from: /Users/gus/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
Reason: tried: 'libssl.1.1.dylib' (no such file), '/usr/local/lib/libssl.1.1.dylib' (no such file), '/usr/lib/libssl.1.1.dylib' (no such file), '/Users/gus/gus_project/Gus2021/libssl.1.1.dylib' (no such file), '/usr/local/lib/libssl.1.1.dylib' (no such file), '/usr/lib/libssl.1.1.dylib' (no such file) - /Users/gus/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
If anyone runs into this problem, this is what solved my issue.
paths to openssl needed to be updated.
gem install mysql2 -- --with-ldflags=-L/opt/homebrew/opt/openssl#1.1/lib --with-cppflags=-I/opt/homebrew/opt/openssl#1.1/include
bundle install
Obviously this is for openssl install with brew install version 1.1
I was able to get it working with this:
brew install openssl
bundle config build.mysql2 --
--with-ldflags=-L/opt/homebrew/opt/openssl#1.1/lib
--with-cppflags=-I/opt/homebrew/opt/openssl#1.1/include
brew install openssl#1.1
Do all the export path things, and make sure to link openssl#1.1
brew link openssl#1.1 --force
I had similar issue with postgresql, which raises error while running psql -d database:
Library not loaded: '/opt/homebrew/opt/openssl#1.1/lib/libssl.1.1.dylib'
In my case which I have openssl#3 and openssl# the solution is:
brew install openssl#1.1
brew link openssl#1.1 --force
Then reinstall postgresql with homebrew.
I also had my zshrc exporting the following ENV variable though I'm not quite sure if it's related:
export PATH="/opt/homebrew/opt/openssl#1.1/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl#1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl#1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl#1.1/lib/pkgconfig"
For someone who runs into the same issue as mine!

ruby mysql2 gem install error

I am having problems installing mysql2 gem on my windows machine, usually it worked, but now I get Failed to build native extension. I googled around, but there were a lot of linux fixes. I know its not the best thing to work on windows with ruby. Back to the problem, I used gem install mysql2 -- --with-mysql-dir=C:\wamp\bin\mysql\mysql5.6.12\bin --with-mysql-lib=C:\wamp\bin\mysql\mysql5.6.12\lib to install mysql2, it works with mysql, but rails requires mysql2.
Thank you.
mysql2 can be tricky to install. We JUST got a dev box working with Ruby 2.0.0p247, Windows 64bit and mysql 0.3.13. Here are some suggestions:
Make sure you have the latest DevKit installed (http://rubyinstaller.org/downloads/). On the right column of the page, it tells you which version of the DevKit you'll need for your particular version of Ruby. We've found it was easiest to install it to C:\DevKit
Now try and run the gem install mysql2 ... command you listed in your question. Alternatively, for 32bit installs we do:
subst X: "C:\Program Files (x86)\MySQL\MySQL Server 5.6"
gem install mysql2 -v=0.3.13 --platform=ruby -- --with-mysql-include=X:\include --with-mysql-lib=X:\lib
subst X: /d
The subst command creates a virtual drive and helps with the spaces in the path name.
Copy the C:\Program Files (x86)\MySQL\MySQL Server 5.6\lib\libmysql.dll to your Ruby bin directory. You should be off and running if you're working with 32bit.
64bit users however will likely run into another bug once they get mysql2 to build. The above steps will appear to work, but when they actually go to use the mysql2 gem to do something useful, like run rake db:create, they get a segmentation fault. More info and a fix for the issue can be found at https://github.com/brianmario/mysql2/issues/372, https://bugs.ruby-lang.org/issues/8591, https://groups.google.com/forum/#!topic/rubyinstaller/uTNffOt6Yqo
Long story short, a compatible mysql connector c needs to be used instead of the MySQL server directory. A helpful user provided the right connector c and it can be downloaded here (https://www.copy.com/s/CHZ4eT4us6f1/mysql-connector-c-noinstall-6.0.2-winx64.zip). Extract that zip file, and point your gem install mysql2 ... command to the appropriate directories and 64bit happiness will follow. (Don't forget to grab the libmysql.dll from the downloaded connector c folder and place it in your ruby bin directory).
Execute this command in command prompt.
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"'
note: change the Mysql installation directory as per your installation.
That should work perfectly
Download the 32-bit Zip Archive of connector from here. Then copy the extracted folder to the root of your C drive for ease of access so that your connector folder path will be something like this
C:\mysql-connector-c-6.1.3-win32\
Now copy this line of code to your cmd and execute (remember to change the connector version number with your one)
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-connector-c-6.1.3-win32/"'
After trying for a long time I successfully installed mysql2 gem in both of my 32 and 64 bit windows 7 in this way. Cheers!

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.

Rails Error - No Such File to Load -- mysql

I've been fighting with a Rails install on my Mac for some time. The error I'm getting (in my development log) says:
Status: 500 Internal Server Error no such file to load -- mysql
Here's some info:
I can successfully rake db:migrate my application.
I've installed the MySQL gem and it appears in the gem list: mysql (2.8.1).
I have Passenger installed.
The error comes from an existing rails app that works on our production server.
Creating a new Rails app, a new MySQL db (using mysqladmin -uroot create sampledb) works fine.
I've googled this and can't find anything specific to this error. There are a few related results where the solutions relate to paths when installing the MySQL gem. For example,
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
Has anyone else experienced this issue or suggest a solution?
Thanks for the response - the good news is, the problem is solved.
The bad news - I'm not entirely sure what fixed it. I can tell you this: it had something to do with the mysql gem install and all the flags pointing to lib, include and config. There are probably a dozen different versions of the same command floating around out there for Mac OS X Leopard.
The odd thing was that ruby appeared to be connected to mysql on some level (it's ability to rake db for example) but broke when actually loading a page.
The gem install string that ended up working was this:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I'd love some clarification on the how's & why's of this. This worked for me, but doesn't include pointers to the app directory, the lib directory or the include directory.
Do you have multiple ruby installed? Try invoking this command to find out: whereis ruby
Which ruby version is you passenger using? You can check this from your apache or nginx configuration
Is the ruby version passenger is using the same as ruby you are using from the command line?
Is mysql gem installed on that ruby version?
Double check if the mysql bin path is in your $PATH system environment variable. If you execute
*echo $PATH*
there must be displayed something like
*/usr/local/mysql/bin*
You can also type
mysql and then the tab-key twice.
If if this doesn't bring up a list of mysql commands (like mysqladmin etc.) the mysql bin path is not set ccorrectly. You can set it by adding the correct directory to your bash profile file.
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
Please verify up front if
*/usr/local/mysql/bin*
really contains the mysql commands on your Mac. Important: close and reopen the terminal window to make changes work.

Rails 3 Mysql Problems

Trying to start a new Rails 3 beta 4 app with mysql.... Running OS X Snow Leopard. WIth previous versions of Rails I have no problem with MySQL. But now when I start the Rails 3 app I get the following error when I click "About Your Application Environment" on the Rails index.html startup screen:
undefined method `init' for Mysql:Class
Change your Gemfile to use 'mysql2', it's a more modern driver and has nicer features as other people have mentioned.
New Rails applications use the mysql2 gem by default.
I ran into the same issue (RoR 3, OSX 10.6, mysql 2.8.1 gem).
You can use irb to rule out RoR:
irb
require 'rubygems'
require 'mysql'
db = Mysql.connect('hostname', 'username', 'password', 'database')
If the above doesn't work, you may want to try removing the mysql gem and reinstalling it. I came across a post saying bundle install might mess up the install without displaying errors.
sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Verify things work via irb, then start up rails again.
I ended up switching from the mysql gem to the ruby-mysql gem, worked.
For simple usage, which is typical (connecting, querying, iterating over results), I found mysql2 gem which is much faster than mysql or ruby-mysql gems and auto-casts values to proper types. And it installes perfectly on Snow Leopard while I couldn't get mysql gem to work.
More info at http://github.com/brianmario/mysql2
I think I have found the solution for the problem. In my case the problem was that the mysql gem hasn't been properly installed using the bundler . when I did this:
bundle install mysql (noobish mistake)
all gems went to mysql directory, but later on I have checked the docs of the bundler gem
and did this:
bundle install bundler_files ( to know where the gems are in the future)
everything looked almost ok except that when mysql gem was installing i got some errors.
I noticed that it was because of my folder path "/home/pawel/Aptana Studio Workspace/myrails_app"
If you have spaces in your folder path this gem wont install properly and later on when you modify the path to one without spaces and try to install the mysql gem IT WONT DISPLAY ANY ERRORS, but the installation will be corrupted, because you will have some extra folders there with some files etc. so
DELETE THE GEM FOLDER CREATED BY BUNDLER AND REINSTALL GEMS WITH THIS COMMAND:
bundle install
That solved the problem.
you can try switching to the mysql2 gem which should resolve all that issues for you. see: https://github.com/brianmario/mysql2/
I think what happens is that the mysql gem isn't able to load the mysql dynamic library (supposed to be supplied by the native MySQL installation). To test whether this is happening, do this
$ irb
1.9.2p320 :001 > require 'mysql_api'
=> true
1.9.2p320 :002 >
If it isn't able to load this low level mysql_api, (which actually supplies the functionality to the mysql gem), it will give you some potentially useful errors. Usually it is not able to find the dynamic library. To remedy this, I found a couple of solutions:
From http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard, do this
For system-wide install
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
or local install
env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
and then from http://alexbraunstein.com/2011/08/12/library-loaded-libmysqlclient-18-dylib/ put in .bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
I has the same issue after upgrading to Snow Leopard. On installing the MySQL gem, I got a bunch of errors about the documentation, then, on running the server:
undefined method `init' for Mysql:Class
I was also having some similar, but unrelated issues with other gems, particularly those that had C components that needed compiling such as RedCloth and hpricot:
Unable to compile native extensions
These errors were to do with native extensions in base 64 architecture. The solution was threefold:
I reinstalled XCode 4. The upgrade to Snow Leopard had broken my C compiler, so some gems were failing to compile. This took me a step closer, but didn't fix the issue.
I blew away and reinstalled RVM. It appeared to be installing gems in one directory, and finding them in another. This fixed every native architecture base64 error, but the MySQL gem was still failing.
I removed and downgraded MySQL to version 5.1. This fixed the MySQL gem issue.
All is now well again.