New install of cent os 5.4; clean install of percona xtradb server (Server version: 5.1.56-rel12.7 Percona Server (GPL), 12.7, Revision 224) gem install mysql failed with the output
/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... yes
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
which appears to indicate it can't find the dev libraries. I know I'd normally use the additional options -- --with-mysql-lib=... but I don't believe they're installed as part of the normal percona install outlined here: percona repositories info
So I tried doing yum install mysql-devel but get a conflict with the percona stuff. I found this post where the proposed solution was using the --with-mysql-config option. Percona doesn't automatically install a my.cnf at /etc/my.cnf upon installation, so I whipped one up and placed it there because that's where the init.d script for mysql checks for it. Restarted mysql, confirmed that it's now loading that configuration and attempted the install again, but still failed with
"Exec format error - /etc/my.cnf --cflags (Errno::ENOEXEC)"
Thanks for any help
I also did a find / -name mysql.h and nothing, so it looks like the required libraries are not present after installing both percona server and client with yum
If you correctly added Percona yum repository you just need to install the Percona-Server-devel package:
yum install Percona-Server-devel-55
Replace 55 with the Percona Server version you're currently using.
After that, mysql gems will install correctly.
I've reinstalled libmysqlclient-dev from Percona.
And then reinstalled mysql & mysql2 gems.
After troubling hours and hours and many hours:
Found the following to install mysql gem with percona 5.6:
http://www.percona.com/doc/percona-server/5.6/release-notes/Percona-Server-5.6.16-64.1.html
gem uninstall mysql
apt-get remove mysql-server mysql-server-5.5 mysql-client
mysql-client-5.5 mysql-client-core-5.5 mysql-server-core-5.5
mysql-common libmysqlclient18:i386 libmysqlclient18:amd64
apt-get install percona-server-server-5.6 percona-server-client-5.6
cd /usr/lib/x86_64-linux-gnu
mv libmysqlclient.so.18.0.0 libmysqlclient.so.18.0.0-backup
ln -s libperconaserverclient.so.18.1.0 libmysqlclient.so.18.0.0
rm -rf /home/slat/.rvm/gems/ruby-XXXXX/gems/mysql*
gem install mysql
YIHAA - It works!
For any new people trying to install this gem (this question shows up highly in search ranks), make sure you're passing the mysql directory, like:
gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
Related
I am running Ruby v2.3.3 on Debian 9.6. I executed this command in the terminal: sudo gem install mysql.
This gave me an error.
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.
Here's the full text of the error: https://pastebin.com/raw/HZcL2UtF
Here's the contents of mkmf.log: https://pastebin.com/raw/Bki5e9tT
Why can't I install the mysql gem? How do I fix this error?
Usually that means that you don't have required mysql libs on your system.
Try execute:
sudo apt-get update
sudo apt-get install libmysqlclient-dev libmysqlclient16
Then run mysql gem installation again:
sudo gem install mysql
By wrong uninstalling MariaDB, I've lost working instance of MySQL and MariaDB in my Ubuntu 16.04 system...
I've broken the dependencies so much, that I can not uninstall or install MySQL or MariaDB, using apt-get, or dpkg...
All the following commands failed:
apt-get [install -f] [update] [remove] [purge] [autorove] [clean] [check]
and options with dpkg such as:
dpkg --remove --force-remove-reinstreq mysql
also don't help me.
Manually downloading the package and attempting to install from a local file did not help.
For each installation, uninstallation or other attempt, I get almost the same result:
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
mariadb-client : Depends: mariadb-client-10.0 (>= 10.0.34-0ubuntu0.16.04.1) but it is not installed
mariadb-server-10.0 : PreDepends: mariadb-common (>= 10.0.34-0ubuntu0.16.04.1) but it is not installed
Depends: mariadb-client-10.0 (>= 10.0.34-0ubuntu0.16.04.1) but it is not installed
Breaks: mysql-server
mariadb-server-core-10.0 : Depends: mariadb-common (>= 10.0.34-0ubuntu0.16.04.1) but it is not installed
mysql-server : Depends: mysql-community-server (= 5.7.22-1ubuntu16.04) but it is not installed
E: Unmet dependencies. Try using -f.
Is there any different way to permanently remove any traces and remnants of MySQL and MariaDB from the operating system, so that I can reinstall MySQL itself?
I need to working with MySQL, but I can't reinstall the operating system.
Please help me.
God exists! :D
The problem was solved by entering:
sudo apt-get -f install
without any other parameters
and later displaying all packages via:
sudo dpkg -l | grep mariadb
sudo dpkg -l | grep mysql
and removing problematic packages in the right order:
sudo apt-get --purge autoremove package_name
After the complete removal of all problematic packages, I could re-install MySQL without any problems...
Thank you #YuriLachin for your help.
It is probably better to address the question to serverfault.com.
Run:
dpkg --audit
to find what is broken.
Then run:
dpkg --list|grep -i mysql
and
dpkg --list|grep -i mariadb
Look at the first (status) column and, optionally, inspect detailed status for some of packages with:
dpkg-info -s <name-of-package>
Then you can try to remove found mysql/mariadb related packages with
dpkg -remove --force-remove-reinstreq <package-list>
As a way around you can always run mysq in docker container without mysql being installed
Im trying to install an open source rails 3.2.21 application that uses the mysql2 gem, but when i try and run the bundle commant I get the following error:
Fetching: mysql2-0.3.18.gem (100%)
Building native extensions. This could take a while...
p
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
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
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/5.6.25/lib
-----
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/travis/.sm/pkg/active/lib'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86
I tried uninstalling every version of mysql I installed via homebrew and reinstalling them, like so:
brew uninstall --force mysql && brew install mysql
Then running:
sudo gem install mysql2
As suggested by a number of similar questions asked on here, but it still results in the same error as above.
Please could someone offer guidance on how to get this up and running?
For anybody still experiencing the issue:
When you install openssl via brew, you should get the following message:
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
You can set these build flags (for the local application) by running the following:
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
This worked for me.
See bundler's documentation for more information.
The error log says:
ld: library not found for -lssl
So, you need to install libssl:
brew install openssl
As it was pointed out in comments, there might be a need to export the path to the library.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Try this:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
(Update version as appropriate)
The solution for me was to install the Xcode Command Line Tools.
I had recently updated Xcode through the Mac App Store, and every time I do that, I've found that I have to reinstall the Command Line Tools again.
xcode-select --install
Based on the solution here
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
solved the problem.
After Homebrew update (openssl#1.1) there is a new path for libs, so may use:
bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)
bundle install
It will fix ld: library not found for -lssl error
Thanks #mudasobwa for pointing me in the right direction. It turns out the error was caused by an unlinked openssl file, so running:
brew reinstall openssl && brew link openssl --force
Solved the problem. I found the solution here: OpenSSL, RVM, Brew, conflicting error
On MacBook air M1(macOS) it worked for me.
Install zstd
brew install zstd
Install mysql2
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
From here:
https://gorails.com/setup/osx/10.14-mojave
The combination of commands solved it me. I am on Mojave.
brew reinstall openssl && brew link openssl --force
and then
gem install mysql2 -v '0.4.10' -- \
--with-ldflags=-L/usr/local/opt/openssl/lib \
--with-cppflags=-I/usr/local/opt/openssl/include
Steps for me on Monterey M1 Mac
brew install openssl#3
brew install zstd
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
bundle config --local build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib"
bundle install
Seems that you miss the main files needed to build mysql2 gem
sudo apt-get install libsqlite3-dev libmysqlclient-dev -y
libsqlite3-dev is not mandatory but install it since it's the default rails DB.
Mac Catalina using Homebrew fix:
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
the following command works for my Mac os 12.1 MacOs Monterey
gem install mysql2 -v '0.5.3' -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include
Please refer this link for more details
https://github.com/brianmario/mysql2/issues/1175
This finally worked for me on macOS Monterey 12.3 (M1 Pro):
gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1
Make sure you read the installation instructions. Notable points for me were:
Make sure MySQL is installed (brew install mysql)
Make sure XCode select tools are installed (xcode-select --install)
Set the with-mysql-dir option to wherever mysql was installed (check with brew info mysql)
Combining the answers given by Aleksei Matiushkin and Alexey Mozorov fixed the problem for me.
But I also updated the openssl before adding the path.
Thanks!
I've been coding with mysql2 gem for years and have encountered with this issue time to time.
Today I found that this magic option -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include no longer worked on my Mac. Indeed, it looks like the default location where brew installs openssl has changed:
$ brew reinstall openssl
...
If you need to have openssl#3 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl#3/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl#3 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl#3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl#3/include"
So following the message, I had to make a few changes to the command and got it work finally:
$ gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/opt/homebrew/opt/openssl#3/lib --with-cppflags=-I/opt/homebrew/opt/openssl#3/include
Hope this will help someone!
This helped me on MacOs 12.6 (Monterey)
brew install mysql openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
gem install mysql2 -v '0.5.3' \
--source 'https://rubygems.org/' -- \
--with-cppflags=-I/usr/local/opt/openssl/include \
--with-ldflags=-L/usr/local/opt/openssl/lib
bundle install
Thanks https://github.com/brianmario/mysql2/issues/1175#issuecomment-1069721834
I found that I had to use --with-opt-dir=/usr/local/opt.
Specifically, I added the following to my ~/.bundle/config file:
BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt"
On RedHat 7 (ec2 image provided by AWS), I'm unable to install the json gem:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h
I've tried all manner of packages libyaml-devel etc and nothing seems to work.
I've already run through:
Error while installing json gem 'mkmf.rb can't find header files for ruby'
sudo rpm -Uvh ftp://195.220.108.108/linux/centos/7.0.1406/os/x86_64/Packages/ruby-devel-2.0.0.353-20.el7.x86_64.rpm
This seemed to fix it since sudo yum ruby-devel doesn't work.
rhel tucks things like this away in the 'optional' repo... you can enable this for aws/ec2 supplied images in:
/etc/yum.repos.d/redhat-rhui.repo
[rhui-REGION-rhel-server-optional]
name=Red Hat Enterprise Linux Server 7 Optional (RPMs)
mirrorlist=https://rhui2-cds01.REGION.aws.ce.redhat.com/pulp/mirror/content/dist/rhel/rhui/server/7/$relea$
**enabled=1**
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify=1
sslclientkey=/etc/pki/rhui/content-rhel7.key
sslclientcert=/etc/pki/rhui/product/content-rhel7.crt
sslcacert=/etc/pki/rhui/cdn.redhat.com-chain.crt
Or just do a one-time install:
yum install ruby-devel --enablerepo=rhui-REGION-rhel-server-optional
And if you are using subscription-manager:
subscription-manager repos --enable=rhel-7-server-optional-rpms
Then: sudo yum install -y ruby-devel
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.