80

I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql and I receive the following:

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 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

I've searched, and tried a whole host of things, from installing specific versions to trying to reinstall ruby without any luck.

Any ideas where I may be going wrong?

I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql and I receive the following:

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 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

I've searched, and tried a whole host of things, from installing specific versions to trying to reinstall ruby without any luck.

Any ideas where I may be going wrong?

EDIT: I installed XCode off my Snow Leopard DVD and the error just changed slightly to the following:

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 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:17: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lmygcc... no checking for mysql_query() in -lmysqlclient... 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 --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysqlclientlib --without-mysqlclientlib --with-mlib --without-mlib --with-mysqlclientlib --without-mysqlclientlib --with-zlib --without-zlib --with-mysqlclientlib --without-mysqlclientlib --with-socketlib --without-socketlib --with-mysqlclientlib --without-mysqlclientlib --with-nsllib --without-nsllib --with-mysqlclientlib --without-mysqlclientlib --with-mygcclib --without-mygcclib --with-mysqlclientlib --without-mysqlclientlib

Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

doing "which mysql" on the command line returns nothing, which means it's not recognizing it. I also installed the MySQL system preferences option, and I can't stop MySQL from running. Now I'm completely stuck as what to do!

EDIT EDIT

I've just completely reinstalled MySQL using this guide http://hivelogic.com/articles/installing-mysql-on-mac-os-x

Unfortunately this didn't work either, I still receive the same errors. I can't even do mysql -uroot at the command line, I get the error of:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

So I think I've tried everything.

**SOLVED*

Sorry guys, the reason for this not working was because of the MySQL paths. I've blogged on it here: http://www.kieransenior.co.uk/2010/02/mysql-cant-connect-using-ruby-on-rails-mac-os-x-snow-leopard/

Kieran Senior
  • 17,960
  • 26
  • 94
  • 138

15 Answers15

174

On Debian (or Ubuntu) systems, just install libmysqlclient-dev package using:

sudo apt-get install libmysqlclient-dev

and then:

gem install mysql

It will be installed without any error.

cartoonist
  • 5,991
  • 6
  • 37
  • 40
64

Installing the mysql gem on OSX

in a terminal.. First do a ‘locate mysql_config’ and then replace the path in the following command with where that file is.

$ sudo gem install mysql -- —–with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while…
Successfully installed mysql-2.7
1 gem installed
Trevoke
  • 4,115
  • 1
  • 27
  • 48
  • 2
    I installed XAMPP for OSX, so my command was: ```gem install mysql -- --with-mysql-config=/Applications/XAMPP/bin/mysql_config```. No sudo required! – thesmart Nov 06 '13 at 21:23
  • 1
    Just fyi. I was still not able to install, but then I realized that /usr/local/mysql/bin was not on my PATH env variable. Once I got that on my PATH, I was able to install it without a problem. – justspamjustin Jan 28 '14 at 14:02
  • 3
    I had to `sudo locate mysql_config` to get the config paths. Otherwise, it return the message: `WARNING: The locate database (/var/db/locate.database) does not exist. ...` – RNickMcCandless Jul 22 '14 at 22:47
  • I had to install xcode command line tools before this answer would ultimately work for me. See this related answer: http://stackoverflow.com/questions/761521/when-i-try-sudo-gem-install-json-i-get-the-following-error/19532316#19532316 and then try `sudo gem install mysql1 etc` like in this answer :) – Josh Burson Mar 16 '15 at 23:33
  • @JoshBurson If you want a _complete_ guide to installing mysql from scratch on OSX, I think it's a wholly different story. – Trevoke Mar 16 '15 at 23:49
  • Absolutely. I wasn't, however, installing from scratch. I commented to help others who may be running into issues like I was. – Josh Burson Mar 17 '15 at 00:03
17

First of all you need to differentiate between the MySQL as Server, MySQL as Client and the Ruby bindings to MySQL.

I'm not familiar with Mac, but for *nix OS you need to install MySQL through your package manager. To get the Ruby bindings installed with

gem install mysql

you need the development headers of ruby (in Ubuntu it is the package ruby-dev) and the development headers of the MySQL-Client (currently libmysqlclient16-dev in Ubuntu). I don't know if they are named different on Mac, but after you got those installed the Ruby bindings should install without any error.

Aurril
  • 2,469
  • 2
  • 24
  • 38
  • Indubitably, there is a multi-packaged version which does both. I've gone through this process as well. I think you're right, I do need to differentiate between the two as this has been mainly my problem. Another option, perhaps, is to install MAMP and use that? What would I need then? – Kieran Senior Feb 03 '10 at 13:00
  • MAMP stands for Mac, Apache, MySQL, Php. So you would still need a MySQL-Server and in addition Apache 2, and the php libraries for apache. I'm not sure if you can just select MAMP in your package manager and it will install all required files. Maybe a Mac user could help you out there. – Aurril Feb 03 '10 at 13:45
  • Indeed it would fall short of the need for MAMP, but it was just an easy way to serve up a MySQL instance. – Kieran Senior Feb 03 '10 at 14:17
  • 4
    This was exactly what I needed on Ubuntu: `sudo apt-get install ruby-dev` and `sudo gem install mysql`. Thanks! – Dan Breslau Feb 26 '10 at 21:37
  • 1
    yep, this worked: 'sudo apt-get install ruby-dev libmysqlclient16-dev' then 'sudo gem install mysql' – Travis Reeder Sep 07 '10 at 23:47
  • Thanks Aurril - ruby-dev is what was missing in my case! – nevelis Oct 06 '10 at 10:27
9

A number of people found this post helpful.

Also, I needed to do first type this:

yum install mysql-devel

and then:

gem install mysql 

For some people you may need to type:

gem install mysql -- --with-mysql-config=/usr/local/mysql/mysql_config
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Guy Saban
  • 91
  • 1
  • 2
  • Dude, If I could give you 2 up I would! Although is good to note that this yum command may only be useful with some flavors of LINUX. In my case CentOS 6.0 – Onema Mar 15 '12 at 18:20
5

on OSX mountain Lion: If you have brew installed, then brew install mysql and follow the instructions on creating a test database with mysql on your machine. You don't have to go all the way through, I didn't need to After I did that I was able to bundle install and rake.

0bserver07
  • 3,390
  • 1
  • 28
  • 56
downrightmike
  • 51
  • 1
  • 3
4

I had a similar experience, so here are the things that I tried

Firstly, I tried to install mysql's required packages by running the command below in my terminal

sudo apt-get install build-essential libmysqlclient-dev

Secondly, I tried updating rubygems on my system by running the command below in my terminal

sudo gem update --system

But I was still experiencing the same issue.

Here’s what worked for me

After much research I realized that I was using an almost out-of-date version of the mysql gem. I simply needed to use the mysql2 gem (mysql2 gem)and not the mysql gem, so I fixed it by running the command below in my terminal

gem install mysql2

This worked fine for me. Before running the last command, ensure that you've ran the first and second commands to be sure that everything is fine on your system.

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
3

In order to resolve

Gem::Ext::BuildError: ERROR: Failed to build gem native extension error for mysql2,

I think libmysql-ruby got changed with ruby-mysql

Simply try with following commands,

sudo apt-get install ruby-mysql

& then

sudo apt-get install libmysqlclient-dev
rahul patil
  • 657
  • 6
  • 12
2

I had also forgotten to actually install MySQL in the first place. Following this guide helped a lot.

http://www.djangoapp.com/blog/2011/07/24/installation-of-mysql-server-on-mac-os-x-lion/

As well as adding these lines to my .profile:

export PATH="/usr/local/mysql/bin:$PATH"
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
Richard Burton
  • 2,230
  • 6
  • 34
  • 49
0

If you use Percona Mysql server

$ yum install Percona-Server-devel-55

$ gem install mysql

AlexeyKa
  • 558
  • 3
  • 9
0

you can try to reinstall the latest version of xcode / dev. tools for snow leopard - this should fix your errors

roman
  • 11,143
  • 1
  • 31
  • 42
0

if you are installing from source here is a tutorial.would be happy if it helps http://raihan90.blogspot.com/2009/03/mysql-step-by-step-hacking-into-mysql.html

Raihan Alam
  • 91
  • 1
  • 8
0

Attention: You need to specify -- key, and than --with-mysql-config=/usr/local/mysql/bin/mysql_config

Vestel
  • 1,005
  • 1
  • 11
  • 25
  • 1
    Again, this answer is floating in many-a-place. In my instance, it doesn't work. Plus, mysql didn't exist for me in /usr/local/ I believe. – Kieran Senior Feb 03 '10 at 14:18
0
yum -y install gcc mysql-devel ruby-devel rubygems
gem install mysql2
austin
  • 5,816
  • 2
  • 32
  • 40
0

Your Ubuntu OS need to install library for mysql client sudo apt-get install libmysqlclient-dev

After That just install bundle or bundle install

0

While these answers pointed me in the right direction, on Alpine linux the package I needed was mariadb-dev, eg. run apk add mariadb-dev before the gem install mysql command.

Yep_It's_Me
  • 4,494
  • 4
  • 43
  • 66