MySQL Gem installation error on Rails - mysql

I am deploying my Rails application using Chef. While
gem install mysql
am getting hte following error,
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native
extension.
/opt/chef/embedded/bin/ruby extconf.rb checking for
mysql_ssl_set()... * 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/chef/embedded/bin/ruby --with-mysql-config
--without-mysql-config
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:381:in try_do': The
compiler failed to generate an executable file. (RuntimeError) You
have to install development tools first. from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:461:intry_link0' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:476:in try_link' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:619:intry_func' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:894:in block in have_func'
from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:790:inblock in
checking_for' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in
block (2 levels) in postpone' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:inopen' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in block in postpone'
from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:inopen' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:280:in postpone' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:789:inchecking_for' from
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:893:in have_func' from
extconf.rb:45:in'
Gem files will remain installed in
/var/www/project-name/releases/daf93f4783a7238e5a8198c1fd50e4e1de93f654/vendor/bundle/ruby/1.9.1/gems/mysql-2.9.1
for inspection. Results logged to
/var/www/project-name/releases/daf93f4783a7238e5a8198c1fd50e4e1de93f654/vendor/bundle/ruby/1.9.1/gems/mysql-2.9.1/ext/mysql_api/gem_make.out
An error occured while installing mysql (2.9.1), and Bundler cannot
continue. Make sure that gem install mysql -v '2.9.1' succeeds
before bundling.
I am using RHEL 6. I also have a separate cookbook for mysql installation. I tried installing Mysql manually using the yum command.
I tried
yum install mysql-devel and then run the gem install mysql
still not working. Can anyone help me out.
Thanks

It sounds like you don't have a compiler. On a debian/ubuntu system, you can get everything you need to compile and build packages with:
sudo apt-get install build-essential
On Fedora/Red Hat I think it should be:
sudo yum groupinstall "Development Tools"

Add the build-essentials cookbook to your runlist and configure it's "compiletime" attribute.
The following answer reports the same problem building the postgres gem
Issue with installing Postgres on Vagrant VM using Chef: undefined method `ruby' for Config:Module

Related

Can't install mysql gem on Percona-XtraDB-Cluster

I saw there few topics about this problem, but none of them solved my problem.
So. Platform is CentOS 6.6. I have installed Percona-XtraDB-Cluster, their mysql-libs and their devel packages.
Also i have there ruby 2.0.0 and rubygems 2.4.3. Now i am trying to install mysql gem. What i am getting:
Building native extensions. This could take a while... ERROR: Error
installing mysql: ERROR: Failed to build gem native extension.
/opt/sensu/embedded/bin/ruby -r ./siteconf20141114-16854-1fyrg9v.rb extconf.rb checking for
mysql_ssl_set()... * 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/sensu/embedded/bin/ruby --with-mysql-config
--without-mysql-config
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:434:in try_do': The
compiler failed to generate an executable file. (RuntimeError) You
have to install development tools first. from
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:519:intry_link0' from
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:534:in try_link' from
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:720:intry_func' from
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:1004:in block in
have_func' from /opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:895:in
block in checking_for' from
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:340:in block (2 levels) in
postpone' from /opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:310:in
open' from /opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:340:in block
in postpone' from /opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:310:in
open' from /opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:336:in
postpone' from /opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:894:in
checking_for' from
/opt/sensu/embedded/lib/ruby/2.0.0/mkmf.rb:1003:in have_func' from
extconf.rb:45:in'
extconf failed, exit code 1
Gem files will remain installed in
/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/mysql-2.9.1 for
inspection. Results logged to
/opt/sensu/embedded/lib/ruby/gems/2.0.0/extensions/x86_64-linux/2.0.0/mysql-2.9.1/gem_make.out
Any of described solutions, which i found on the web didn't help me, so, maybe someone had similar problems with this Percona cluster and ruby-2.0.0 and gem mysql-2.9.1
Looks like you need development libraries for the Ruby gem MySQL with SSL:
Try each of these:
yum install gcc
yum install mysql mysql-devel mysql-server
yum install openssl openssl-devel
yum install ruby-devel
Then try installing the newer mysql2 gem:
gem install mysql2 --version '>=0.3.17'
Sensu expects SSL, so it is good to have it. The Sensu documentation says " It is possible to use Sensu without SSL, however, it is heavily discouraged. The following instructions use a tool to generate self-signed OpenSSL certificates". Read about how to enable SSL here:
http://sensuapp.org/docs/latest/certificates#documentation
If you want SSL, you may want to ensure that your database does have SSL enabled:
> show variables like '%ssl%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_openssl | YES |
| have_ssl | YES |
...
You wrote in the comment that you can't install mysql-devel and mysql-server because they will conflict with percona. My guess is that the error is the older mysql gem and/or the need for SSL.
If you are using rvm, it can also cause these kinds of glitches. You may want to try ruby-install and installing the current ruby. This may bring in the dependencies you need. If you want, you can use ruby-install in a custom directory, like this:
$ ruby-install ruby 2.1.5 --install-dir ~/foo/bar/
If you are using sudo gem install, it can also cause glitches for native gems. You may want to try becoming root, and using the actual root environment, and the root ruby version, and double-checking that the ruby version is what you expect, like this:
$ sudo su -
# which ruby
# ruby --version
# gem install mysql2 --version '>=0.3.17'

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

mysql gem broken in debian testing?

I've been trying all night, and so far have been unable to compile the mysql gem for ruby on my Debian Testing 64Bit system.
I believe it is because I have the openssl v1.0.0 library installed.
Here is what I get when I try to install (using RVM 1.14.7, and Ruby 1.9.1p431):
gem install mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/home/jarrett/.rvm/rubies/ruby-1.9.1-p431/bin/ruby extconf.rb
checking for mysql_ssl_set()... *** 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=/home/jarrett/.rvm/rubies/ruby-1.9.1-p431/bin/ruby
--with-mysql-config
--without-mysql-config
/home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:364:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:417:in `try_link0'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:421:in `try_link'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:529:in `try_func'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:774:in `block in have_func'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:670:in `block in checking_for'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:276:in `block (2 levels) in postpone'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:250:in `open'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:276:in `block in postpone'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:250:in `open'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:272:in `postpone'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:669:in `checking_for'
from /home/jarrett/.rvm/rubies/ruby-1.9.1-p431/lib/ruby/1.9.1/mkmf.rb:773:in `have_func'
from extconf.rb:45:in `<main>'
Gem files will remain installed in /home/jarrett/.rvm/gems/ruby-1.9.1-p431/gems/mysql-2.9.1 for inspection.
Results logged to /home/jarrett/.rvm/gems/ruby-1.9.1-p431/gems/mysql-2.9.1/ext/mysql_api/gem_make.out
When I checked the mkmf.log file (located at /home/jarrett/.rvm/gems/ruby-1.9.1-p431/gems/mysql-2.9.1/ext/mysql_api/mkmf.log, it was empty).
What I've tried
1) Ensuring all required dev packages are installed (libssl-dev libopenssl-ruby build-essential gcc autoconf automake libmysql-ruby ruby-mysql libmysqld-dev ruby-dev)
2) I originally had a more recent RVM installed - I uninstalled it and reinstalled an earlier version of RVM. I did this (following these instructions: undefined symbol: SSLv2_method when trying to run Thin webserver) in the hope that I could then run rvm pkg install openssl (which installed openssl 0.9.8 locally) and then install ruby with this: rvm install 1.9.1 --with-openssl-dir=/home/jarrett/.rvm/usr. My hope was that this would use the 0.9.8 version of openssl. No dice.
3) Tried exporting the local openssl 0.9.8 to the LD_LIBRARY_PATH with export LD_LIBRARY_PATH=/home/jarrett/.rvm/usr/lib, and then running the install again. No dice.
4) Installing ruby 1.9.2 and 1.9.3 via RVM and trying them. No dice.
5) Yelling at the computer profusely. No dice.
Anyone have any ideas/suggestions?
Maybe is there a chance the mysql gem will be updated to use openssl 1.0.0 soon?
Couldn't figure this out, so I followed these instructions to get openssl 0.9.8 installed (undefined symbol: SSLv2_method when trying to run Thin webserver and https://rvm.io/packages/openssl/), and then installed the mysql2 gem and used that instead.

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.

mysql gem install error in rails

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