mysql gem install error in rails - mysql

I just got put in charge of a new app, one that is already built, to add new features and the like to it. Unfortunately, It was built several years ago (using rails 2.1) and uses mysql (I prefer postgres). I am attempting to install the mysql gem so I can mess about with the code on my local machine and I am getting the following error.
$ sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Password:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** 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.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/local/bin/ruby
--with-mysql-config
Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I checked the directory /usr/local/mysql/bin/mysql_config to make sure the file existed (it does)...I installed mysql with the dmg file (v 5.1) from the mysql site.
Frankly I'm at a loss as for how the hell to fix this. Any suggestions?
Thanks!

I don't think the mysql header files are included in the dmg-file. Install either Homebrew or Macports and run brew install mysql or sudo port -v install mysql5-server mysql5

Related

fail to install mysql2 gem

I'm trying to setup a not so old (but still few years) of Rails project on new Mavericks machine.
When I try to bundle, i keep getting this error (sorry for the long code):
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/royzinn/.rbenv/versions/1.8.7-p352/bin/ruby extconf.rb --with-mysql-config=/usr/local/Cellar/mysql/5.5.20/bin/mysql_config
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. please check your installation of mysql and try again.
-----
*** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/royzinn/.rbenv/versions/1.8.7-p352/bin/ruby
--with-mysql-config
Gem files will remain installed in /Users/royzinn/dailyd/vendor/ruby/1.8/gems/mysql2-0.2.18 for inspection.
Results logged to /Users/royzinn/dailyd/vendor/ruby/1.8/gems/mysql2-0.2.18/ext/mysql2/gem_make.out
Before that I had a message saying that the gem was built for MySQL version 5.5.20 and that I have already activated other (more advanced) MySQL.
I "cleaned" everything with Homebrew, tried to reinstall but nothing seems to work.
Any help is highly appreciated.
Thanks!
Try to delete this directory :
/Users/royzinn/dailyd/vendor/ruby/1.8/gems/mysql2-0.2.18
If this doesn't help delete rvm directory and reinstall
First, make sure the gem can compile on installation.
gem install mysql
If you get an error that the gem won't compile, it may be necessary to install MySQL where Bundler can find it--even though it is included with OS X. Rather than passing paths as arguments to Bundler, just install MySQL with Homebrew and then install the gem.
brew install mysql
gem install mysql2
Finally, the mysql2 gem's version is probably out of date in the Gemfile and needs to be updated.
bundle update mysql2

How do you connect MySQL to Ruby on Rails?

I followed this post, http://blog.teamtreehouse.com/installing-ruby-rails-and-mysql-on-os-x-lion.
I have been learning Ruby and Rails for a month, so I am quite familiar with Ruby. I also know some parts of Rails due to the understandings acquired by following several tutorials.
However, I continuously fail to gem install mysql or gem install mysql2 prior to rails new photos -d mysql.
I already successfully finished brew install mysql and checked mysql -u root.
seodongju#Seoui-MacBook-Pro ~/Desktop/Projects$ sudo gem install mysql2
Password:
Building native extensions. This could take a while...
ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes checking for rb_intern3()... yes checking for mysql.h... no
checking for mysql/mysql.h... no
mysql.h is missing. please check your installation of mysql and try again.
*** 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.
Provided configuration options: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-mysql-config --without-mysql-config
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13 for inspection. Results logged to /usr/local/rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/ext/mysql2/gem_make.out
You should install MySQL on your machine first
Take it from here
http://dev.mysql.com/downloads/installer
After installing it install the Gem

Installing MySQL with rails without Xcode

Is there anyway I could install MySQL gem for rails without Xcode? Many sites have mentioned XCode as optional requirement for installation. But Command line tools is installed.
I have installed rails , ruby, homebrew, MacPorts without XCode.But MySql gem could not be installed
Note: I have installed Command line tools for Xcode. But not full Xcode.
I have followed these references,
http://scotty-t.com/2012/04/02/intstalling-mysql-5-5-on-os-x-mountain-lion/
With setting path in bash_profile
But I keep on getting these errors while trying
sudo gem install mysql
Errors
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
* 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--with-mysql-config
--without-mysql-config
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.9.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.9.0/ext/mysql_api/gem_make.out
Should I install XCode first? Thanks in advance!
While you exec sudo gem install mysql, you're installing a gem which names mysql, not the database. This gem depende on a file named libmysql, which come with the mysql database.
In other words, you have to install mysql db on your machine first, then install the gem. Otherwise, the gem can't build because it can't find the file it need.
Since you have homebrew, you can install mysql db by exec brew install mysql. After that, sudo gem install mysql could work.
Do you have installed mysql-devel ? If not, try this
$ sudo yum install mysql-devel ;sorry it's for fedora
do it for lion, then
$ gem install mysql
If there still is error, try add a config path when you install the gem.

OS X Lion with xampp + rails + mysql2 gem

I'm stuck trying to figure out how to get OS X Lion with a XAMPP installation's MySQL to work with the mysql2 gem in rails.
Here's what I've tried:
Installed the XAMPP Dev Kit
Installed mysql5-server with both port and brew. Both of which I've now uninstalled. As it didn't fix the problem.
Installed mysql5 community edition from DMG file. Now uninstalled as it didn't fix the problem.
Downloaded 32-bit version of mysql5 community edition as a tar. Extracted folder to '/var/mysql'
Here's the command I'm running to try and get it installed:
gem install mysql2 -- --with-mysql-dir=/var/mysql --with-mysql-include=
/var/mysql/include --with-mysql-lib=/var/mysql/lib --with-mysql-config=
/Applications/XAMPP/xamppfiles/bin/mysql_config
I'm at a loss how to get this to work. The only thing I can think of is that I'm somehow not pointing to the directories correctly. I've tried removing /include/, /mysql/ and /lib/ from the with-mysql-include, with-mysql-dir and with-mysql-lib configuration options. No luck with that. I've tried pointing those to the XAMPP installation. No luck still.
The error returned is:
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb --with-mysql-dir=/var/mysql --with-mysql-include=/var/mysql/include --with-mysql-lib=/var/mysql --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing. please check your installation of mysql and try again.
-----
*** 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.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-mysql-config
Gem files will remain installed in /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
It'd be better not to bother with the stuff XAMPP provides, and to just install a fresh copy of MySQL, and simplify your Gem command for installing mysql2:
brew install mysql
gem install mysql2
You were getting errors with installing the gem after installing MySQL through Homebrew because of all this:
--with-mysql-dir=/var/mysql --with-mysql-include= \
/var/mysql/include --with-mysql-lib=/var/mysql/lib --with-mysql-config= \
/Applications/XAMPP/xamppfiles/bin/mysql_config
So removing it solves the problem.

MySQL Ruby Gem install issues

So I know that this question has been asked before, and I have looked through all of the previous answers and still can't find a solution. Hoping you all can help.
The setup: I am running Mac OS X 10.6 Server. I have used the built in MySQL install on web apps and it works great. Now I am trying to run a RoR app that requires MySQL.
So, whenever I enter
gem install mysql
it spits back the following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/Users/admin/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb --with-mysql-config=/var/mysql
*** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/admin/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
--with-mysql-config
extconf.rb:35:in ``': Permission denied - /var/mysql --cflags (Errno::EACCES)
from extconf.rb:35:in `<main>'
Gem files will remain installed in /Users/admin/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql-2.8.1 for inspection.
Results logged to /Users/admin/.rvm/gems/ruby-1.9.2-p180#rails3/gems/mysql- 2.8.1/ext/mysql_api/gem_make.out
So, through my research, I tried to specifically state the location of the MySQL install.
gem install mysql -- --with-mysql-config=/var/mysql
Unfortunately, with the same results.
Any ideas of where to go from here?
Thanks!
Kevin
Kevin,
This article may help you address your problem:
http://rapd.wordpress.com/2007/05/17/battle-against-ror-gem-install-mysql/
On Mac OSX Lion 10.7 this command helped me install the mysql2 gem:
sudo gem install mysql2 -- --with-mysql-lib=/usr/local/Cellar/mysql55/5.5.30/lib --with-mysql-include=/usr/local/Cellar/mysql55/5.5.30/include/
Before this I did install mysql55 via brew like described above.
Your milage may vary, but here's what seemed to work for us. First, ensure you have the right libraries on there first (from Apple):
http://www.opensource.apple.com/other/MySQL-53.binaries.tar.gz
Install those via:
sudo tar -xvf ~/Downloads/MySQL-53.binaries.tar -C /
Then, for our 10.6 Server, the location of mysql_config was different:
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'
Using the above worked with ruby Ruby 2.0 on Windows. I changed the library to just lib instead of lib\opt because lib\opt is not present in MySQL Server 5.5.
I picked the above command from a solution to this problem presented at:
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
I had success with this sudo gem install mysql -v '2.8.1' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
but specifying the mysql version that I need