I tried several ideas ... none of them worked ...
I'm just trying to install mysql2 as a gem. My mysql is working, but every time my system says, that mysql.h is missing ... Has someone an idea? It's very frustrating now ...
I'm using osx 10.8.3, ruby 1.9.3, rails 3.2.13 and home-brew.
gem install mysql2 -v '0.3.11'
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
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/gadreel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
--with-mysql-config
--without-mysql-config
file `which mysql`
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
What worked for me in Mountain Lion Rails install(using Homebrew and RVM) was editing /usr/local/Cellar/mysql/5.XX.XX/bin/mysql_config
and removing -Wno-null-conversion -Wno-unused-private-field from cxflags and cxflags options as follows:
Before:
cflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
After:
cflags="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
After that gem install mysql2 proceeded without hickups
Note: this is probably due to a change introduced to mysql_config after 5.6.10: http://bugs.mysql.com/bug.php?id=69645
Using a package manager like Homebrew or MacPorts makes it fairly straight-forward to fix this. The binary distribution of MySQL direct from Oracle and the one bundled with OS X itself does not have the development headers, of which mysql.h is one of them.
Homebrew would fix it like this:
brew install mysql
MacPorts is very similar:
sudo port install mysql
Both of these install libraries, a command-line client and the associated development headers for the libraries. Enabling the server is optional.
As an alternative, you can get the source direct from Apple and install it whatever way you see fit.
Generally Homebrew is the best way to go.
Installing a gem sometimes involves compiling source. In this case the MySQL gem needs to create the ruby interface by compiling the C code -- you most likely need to install the MySQL development files.
(missed the OSX reference earlier)
You need to install the development headers for mysql, using brew you might need to install a lower version than 8 since some header files are removed from this distribution. For instance the my_global.h is removed, so if you code uses this header you will be forced to install a previous version then 8.
Header File Dependencies
We have started cleaning up header files dependencies, i.e. work on
“include what you use” and on reorganizing header files to remove
build dependencies. We have fixed ambiguous include paths; almost all
should now be from the root. Incrementality has increased a lot after
e.g. my_global.h went away, and sql_class.h was also reduced a fair
bit in weight. Shipped client headers are self-contained and much more
sane. For example, client headers are now platform independent (no
difference between 32- and 64-bit Linux).
brew install mysql#5.7 mysql-client#5.7
If you're using the standard XAMPP this could be the problem, you could probably need to install xampp-devel which is the development package for xampp, this distribution contains mysql headers *.h files as well as other related sources, you can find older versions in here.
you can than copy the include directory in your /Applications/XAMPP/xamppfiles then install gem using this command:
sudo gem install mysql2 -v 0.3.21 -- --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config --with-mysql-include=/Applications/XAMPP/xamppfiles/lib/include/ --no-ri --no-rdoc
this version worked for me, and don't need to include --with-mysql-dir if you specify mysql_config path, and then you should get a similar output:
This could take a while...
Successfully installed mysql2-0.3.21
Parsing documentation for mysql2-0.3.21
Installing ri documentation for mysql2-0.3.21
Done installing documentation for mysql2 after 0 seconds
1 gem installed
you may also need to provide rails with the correct version of libmysqlclient, here is an example using Symlink:
sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
Don't forget in update bundle packages.
Related
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'
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.
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
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
I am trying to install the mysql2 gem via the Bundler, but it keeps dying with the following error:
** executing command
/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions':
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
checking for rb_thread_blocking_region()... 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
--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=/home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
--with-mysql-config
Gem files will remain installed for inspection.
Most things I found via Googling recommended passing the --with-mysql-config parameter to fix it. So, based on:
$ which mysql_config
/usr/bin/mysql_config
I added the following to the Bundler's config:
$ bundle config build.mysql2 --with-mysql-config='/usr/bin/mysql_config'
However, still no luck -- same crash as above.
Since it's dying with the error mysql.h is missing, I checked for that, and it's allegedly around, just can't be found by the Bundler.
$ find / -name mysql.h
/usr/include/mysql5/mysql/mysql.h
Any thoughts?
Answer was similar to the one Wrikken posted -- here's what I did to fix it for the sake of future readers.
(This is for RHEL 5.5 -- similar but different commands apply for Ubuntu/Debian/etc.)
Doing sudo yum list installed will print out all installed packages on your machine (note: yum on RHEL requires you add a Red Hat Network repository [I use EPEL], and run it via sudo).
I had mysql and mysql-server, which explained why MySQL worked fine for every pre-existing app, but no mysql-devel, which is necessary to fix that mysql.h is missing error and similar other build errors.
Long story short, after a mysqldump -u root -ppassword --all-databases > full-dump.sql for safety, it was fixed with a simple
sudo yum install mysql-devel
For Ubuntu have to install following.
libmysqlclient-dev
libmysqlclient16
For Mac with a brew install of mysql the following solution fixed the problem for me:
I edited the mysql_config file in /usr/local/Cellar/mysql/5.6.12/bin and removed the W-compiler options -Wno-null-conversion and -Wno-unused-private-field for cflags and cxxflags.
This solved the problem with "gem install mysql2".
Reference: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html
The above problem will be occured because the mysql-devel package is not properly installed in your system. I will be explain the same in Centos of how to fix it. When you try to install that package using,
yum install mysql-devel
somtimes there will be some clash occurs with the existing packages that gets installed if you install the MySql-Administrative tool and MySQL query browser.
In that case, you need to uninstall all the existing mysql2 packages and install it again.
rpm -qa -last | grep -i mysql
yum remove MySQL-server-5.5.27-1.rhel5
yum remove MySQL-client-5.5.27-1.rhel5
yum remove mysql-gui-tools-5.0r12-1rhel4
yum remove mysql-query-browser-5.0r12-1rhel4-a
So, you can uninstall whatever mysql things displayed with rpm -qa as like above.
Then you can install the mysql-server and mysql-client.
yum install mysql-server
yum install mysql-client
Now you do the installation of mysql-devel package.
yum install mysql-devel
Now there is no package clashes and you can able to install the mysql2 gem.
gem install mysql2 -v '0.3.11'
Now your mysql2 gem will be successfully installed and you are good to go.
I got the same error. and for ubuntu 16. I had to write below command:
sudo apt-get install libmysqlclient-dev
and it work back.
In my case the problem was a misbehaving mysql_config script. When invoked by the command line with the --cflags option it would return a string of options containing:
-Xclang -target-feature -Xclang -aes -Qunused-arguments
For some reason the call to have_header('mysql.h') in the extconf.rb script would fail if those option were included.
What worked for me was to hand edit the mysql_config file removing the reference to those options from the line:
cflags="-I$pkgincludedir -Os -w -pipe -march=native -Xclang -target-feature -Xclang -aes -Qunused-arguments -O2 -g -DDBUG_OFF " #note: end space!
which I rewrote as:
cflags="-I$pkgincludedir -Os -w -pipe -march=native -O2 -g -DDBUG_OFF " #note: end space!
I know this is ancient, but if anyone still gets this zlib error, make certain that you typed:
rvm use
(whatever version you're using)
I could have sworn I did that. Just posting in case anyone is pulling their hair out and this helps. If not good luck. :)
I ran into this issue while bundle installing for redmine on fedora 23. The solution I found was to issue this command - sudo dnf install redhat-rpm-config.
Not only did this fix my issue with installing mysql2, but also for nokogiri and redcarpet.
On my Ubuntu 16.04.4 LTS running mysql Ver 15.1 Distrib 10.0.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2, the following worked:
sudo apt-get install libmariadb-client-lgpl-dev
I saw, that the error message of the current installer suggests running
apt-get install libmysqlclient-dev
This might work as well.