Here is my stack:
RHEL 5.8 x86_64
MySQL 5.5 x86_64
Ruby 1.9.3p345
Rails 3.2.8
I am installing mysql2 0.3.11 gem through bundler and got the error, and the problem seems not to be the same with the popular errors at Ruby gem mysql2 install failing and mysql2 gem installation fails. These are the packages I've already installed for mysql.
[user#local config]$ yum list installed | grep MySQL
Unable to read consumer identity
MySQL-client.x86_64 5.5.29-1.rhel5 installed
MySQL-devel.x86_64 5.5.29-1.rhel5 installed
MySQL-python.x86_64 1.2.3-0.1.c1.el5 installed
MySQL-server.x86_64 5.5.29-1.rhel5 installed
perl-DBD-MySQL.x86_64 3.0007-2.el5 installed
[user#local config]$ yum list installed | grep mysql
Unable to read consumer identity
libdbi-dbd-mysql.x86_64 0.8.1a-1.2.2 installed
The error message is as follows:
Installing mysql2 (0.3.11) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.3-p385/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling result.c
In file included from ./mysql2_ext.h:39,
from result.c:1:
./client.h:42:7: warning: no newline at end of file
compiling mysql2_ext.c
In file included from ./mysql2_ext.h:39,
from mysql2_ext.c:1:
./client.h:42:7: warning: no newline at end of file
compiling client.c
In file included from ./mysql2_ext.h:39,
from client.c:1:
./client.h:42:7: warning: no newline at end of file
client.c: In function a€?rb_raise_mysql2_errora€?:
client.c:98: warning: ISO C90 forbids mixed declarations and code
client.c: In function a€?rb_mysql_client_socketa€?:
client.c:590: warning: ISO C90 forbids mixed declarations and code
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make: *** [mysql2.so] Error 1
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.11 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
try and use
bundle config build.mysql2 --with-mysql-config=/.../mysql_config
or
sudo gem install mysql2 -- --with-mysql-config=/.../mysql_config
Related
I have a problem with an install of mysql gem. This is my error :
gem install mysql -v '2.9.1'
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1/ext/mysql_api
/usr/local/rvm/rubies/ruby-2.4.0/bin/ruby -r ./siteconf20170107-4120-x2dv85.rb extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/usr/local/rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/mysql-2.9.1/mkmf.log
current directory: /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1/ext/mysql_api
make "DESTDIR=" clean
current directory: /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1/ext/mysql_api
make "DESTDIR="
compiling mysql.c
mysql.c: In function ‘stmt_bind_result’:
mysql.c:1320:74: error: ‘rb_cFixnum’ undeclared (first use in this function)
else if (argv[i] == rb_cNumeric || argv[i] == rb_cInteger || argv[i] == rb_cFixnum)
^
mysql.c:1320:74: note: each undeclared identifier is reported only once for each function it appears in
mysql.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign"
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand"
cc1: warning: unrecognized command line option "-Wno-parentheses-equality"
cc1: warning: unrecognized command line option "-Wno-tautological-compare"
Makefile:241: recipe for target 'mysql.o' failed
make: *** [mysql.o] Error 1
make failed, exit code 2
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.4.0/gems/mysql-2.9.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/mysql-2.9.1/gem_make.out
When i try this command sudo gem install mysql -v '2.9.1', it's works, and I read this line to justify it...
sudo gem install mysql -v '2.9.1'
Building native extensions. This could take a while...
Successfully installed mysql-2.9.1
Parsing documentation for mysql-2.9.1
Done installing documentation for mysql after 0 seconds
1 gem installed
I don't understand what happened and how to solved this. If someone could help me...
The mysql gem is one of many gems which doesn't like the unification of the integer types in Ruby 2.4.
Unfortunately, since the mysql gem isn't really maintained anymore, I wouldn't hold my breath for an updated version. As a workaround, you can switch to a Ruby version before 2.4, e.g. Ruby 2.3.3.
Alternatively, you could switch to the mysql2 gem which is actively maintained, has a similar API to the mysql gem and in its latest version is compatible with Ruby 2.4.
Attempting to install a specific version Mysql2 Gem. And I get this:
sudo gem install mysql2 -v '0.3.20'
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.2.3/bin/ruby -r ./siteconf20161017-56699-1dsu6v9.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()... no
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.7.16/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: 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
For reference I ran brew install mysql beforehand and it ran successfully. Also I tried uninstalling all versions of brew's mysql references just in case.
Is there something im missing? I've looked around and most pages point back to making sure you run brew install mysql which I have.
In case I wasn't more clear with my above explanation, the failure I am getting is after successfully running brew install mysql the error is from trying to install the gem afterwards via gem install mysql2 -v '0.3.20'
Any idea?
Thanks
How to make it work on MacOS Mojave.
Make sure openssl is installed on Mac via Homebrew:
brew install openssl
Then install mysql2 gem following this special way:
gem install mysql2 -v 'x.x.x' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
where x.x.x - specified version of the mysql2 gem.
Just for reference what ended up working was xcode-select --install which seemed to install the OpenSSL libraries which took care of the ld: library not found for -lssl issue.
I have recently installed rvm to use rails5 along with rails3.x version in my current system. When i tried to create new rails5 application, i have got the below error
Could not find proper version of railties (3.2.13) in any of the sources
Run `bundle install` to install missing gems.
And when i try to do bundle install, i got stuck with this
gem install mysql2 -v '0.3.11'
Building native extensions. This could take a while...
/home/himanth/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:73: warning: Insecure world writable dir /home/himanth/.rvm/gems in PATH, mode 040777
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/home/himanth/.rvm/rubies/ruby-2.3.1/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling mysql2_ext.c
In file included from ./client.h:11:0,
from ./mysql2_ext.h:39,
from mysql2_ext.c:1:
/home/himanth/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/backward/rubysig.h:14:2: warning: #warning rubysig.h is obsolete [-Wcpp]
In file included from ./mysql2_ext.h:39:0,
from mysql2_ext.c:1:
./client.h: In function 'rb_thread_blocking_region':
./client.h:23:3: error: 'TRAP_BEG' undeclared (first use in this function)
./client.h:23:3: note: each undeclared identifier is reported only once for each function it appears in
./client.h:25:3: error: 'TRAP_END' undeclared (first use in this function)
mysql2_ext.c: At top level:
./client.h:16:1: warning: 'rb_thread_blocking_region' defined but not used [-Wunused-function]
make: *** [mysql2_ext.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/himanth/.rvm/gems/ruby-2.3.1#rails5/gems/mysql2-0.3.11 for inspection.
Results logged to /home/himanth/.rvm/gems/ruby-2.3.1#rails5/extensions/x86_64-linux/2.3.0/mysql2-0.3.11/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
Got stuck with this for quite some time, any help would be much appreciated.
From Terminal try following:
For Ubuntu:
sudo apt-get install mysql-client libmysqlclient-dev
sudo gem install mysql2
For Mac:
brew install mysql
sudo gem install mysql2
try the below:
gem install rails
After that install mysql server
sudo apt-get install mysql-client libmysqlclient-dev
then bundle install
Trying to install mysql2 gem on CentOS 6.4 x64 with MySQL 5.6 installed with rpm.
Getting this:
Installing mysql2 (0.3.11)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/rbenv/versions/1.9.3-p448/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling mysql2_ext.c
compiling result.c
compiling client.c
client.c: In function Б─≤rb_raise_mysql2_errorБ─≥:
client.c:98: warning: ISO C90 forbids mixed declarations and code
client.c: In function Б─≤rb_mysql_client_socketБ─≥:
client.c:590: warning: ISO C90 forbids mixed declarations and code
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make: *** [mysql2.so] Error 1
Gem files will remain installed in /usr/local/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11 for inspection.
Results logged to /usr/local/rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
EDIT:
response from ldconfig -p | grep mysql
libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/libmysqlclient_r.so.16
libmysqlclient_r.so.15 (libc6,x86-64) => /usr/lib64/libmysqlclient_r.so.15
libmysqlclient_r.so.14 (libc6,x86-64) => /usr/lib64/libmysqlclient_r.so.14
libmysqlclient_r.so.12 (libc6,x86-64) => /usr/lib64/libmysqlclient_r.so.12
libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/libmysqlclient.so.16
libmysqlclient.so.15 (libc6,x86-64) => /usr/lib64/libmysqlclient.so.15
libmysqlclient.so.14 (libc6,x86-64) => /usr/lib64/libmysqlclient.so.14
libmysqlclient.so.12 (libc6,x86-64) => /usr/lib64/libmysqlclient.so.12
Before doing anything I would recommend trying this:
sudo yum install mysql-devel
It seems it can't find the libmysql_r.so. Either it isn't installed or the system can't find it because it is not properly configured.
Can you list the MySQL packages you have installed?
Can you find the libmysqlclient_r.so on your system?
Can you give us the output of the ldconfig -p|grep mysql?
If the libmysqlclient_r.so file is not there, you probably don't have the MySQL-client packages installed.
If the proper packages are installed, the libmysqlclient_r.so can be found but it doesn't appear in the output of ldconfig -p, you can update the ldconfig cache by running ldconfig -v. It should pick up the library. Then try to install the gem again.
I also met the same problem.I solved it by rpm -ivh MySQL-shared-5.6.30-1.el6.x86_64.rpm.
I have a clean build system as follows
Ubuntu 11.04
Rvm 1.13.5
Ruby 1.9.3p194
Rails 3.2.3
Gem 1.8.24
MySql 5.5.24-1 (installed in /usr/local)
I am trying to install the mysql2 gem (0.3.11) and getting the following problem:
pal#smurf01:~$ sudo gem install mysql2
[sudo] password for pal:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
compiling client.c
client.c: In function 'rb_raise_mysql2_error':
client.c:98:3: warning: ISO C90 forbids mixed declarations and code
client.c: In function 'rb_mysql_client_socket':
client.c:590:3: warning: ISO C90 forbids mixed declarations and code
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.so
/usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.so when searching for -lmysqlclient_r
/usr/bin/ld: skipping incompatible /usr/local/mysql/lib/libmysqlclient_r.a when searching for -lmysqlclient_r
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make: *** [mysql2.so] Error 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
pal#smurf01:~$
First question: Has anyone got Rails mysql2 running with MySql 5.5.1 on Ubuntu? I have it running on another system with 5.1. The gem description is vague on supported MySql versions.
Second question: Has anyone encountered this problem? I± have battled various library issues with the mysql2 gem over the passed year or so but this seems to be different.
Any assistance is gratefully recieved.
BTW: Reverting back to MySql 5.1 is a valid solution!
Regards
Peter
Or just apt-get install libmysqlclient-dev and then gem install mysql2
So the problem appears to have been a missing library and some links. Doing the following solved the issue.
Get the new and install the libmysqlclient-dev deb package kindly provided by Nathan Rennie Waldock
wget http://ppa.launchpad.net/nathan-renniewaldock/ppa/ubuntu/pool/main/m/mysql-5.5/libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb./;l
dpkg -i libmysqlclient-dev_5.5.24-1~ppa1~natty_amd64.deb
Then create some links that mysql2 needs as it can't seem to follow the mysql path
cd /usr/lib/
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.a .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18 .
ln -s /usr/local/mysql-5.5.24-linux2.6-x86_64/lib/libmysqlclient_r.so.18.0.0 .
Now happily install the mysql2 gem
sudo gem install mysql2
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysq2l-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
Had the same issue in Ubuntu 12.04 also using the ppa mentioned in the accepted answer.
But also there was no libmysqlclient file on my system with _r in the name.
Googling around I found out that package builders have started to drop the _r suffix from the files, so that might have happened between 11.10 and 12.04.
Also the paths were a bit different to the once mentioned so these are the symlinks that I had to create:
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.a ./libmysqlclient_r.a
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so ./libmysqlclient_r.so
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 ./libmysqlclient_r.so.18
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0 ./libmysqlclient_r.so.18.0.0
I had this problem as well...
I did dpkg -r mysql-devel as when I was trying to do apt-get install libmysqlclient-dev I got an error saying:
Unpacking libmysqlclient-dev (from .../libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb) ... dpkg:
error processing
/var/cache/apt/archives/libmysqlclient-dev_5.5.24-0ubuntu0.12.04.1_i386.deb
(--unpack): trying to overwrite '/usr/bin/mysql_config', which is
also in package mysql-devel 5.5.28-2
After doing this, gem install mysql2 worked! yay :)