ChatGPT解决这个技术问题 Extra ChatGPT

MySQL Install: ERROR: Failed to build gem native extension

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/


c
cartoonist

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.


Great! Worked in Ubuntu 14.10 64 bits
Worked for me too, Ubuntu 14.4 LTS trusty
T
Trevoke

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

I installed XAMPP for OSX, so my command was: gem install mysql -- --with-mysql-config=/Applications/XAMPP/bin/mysql_config. No sudo required!
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.
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. ...
I had to install xcode command line tools before this answer would ultimately work for me. See this related answer: stackoverflow.com/questions/761521/… and then try sudo gem install mysql1 etc like in this answer :)
@JoshBurson If you want a complete guide to installing mysql from scratch on OSX, I think it's a wholly different story.
A
Aurril

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.


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?
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.
Indeed it would fall short of the need for MAMP, but it was just an easy way to serve up a MySQL instance.
This was exactly what I needed on Ubuntu: sudo apt-get install ruby-dev and sudo gem install mysql. Thanks!
yep, this worked: 'sudo apt-get install ruby-dev libmysqlclient16-dev' then 'sudo gem install mysql'
S
Sathyajith Bhat

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

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
0
0bserver07

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.


This was the only solution that worked for me! Cheers mate!
r
rahul patil

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

P
Promise Preston

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


this command saved me gem install mysql2 thank you
R
Richard Burton

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

r
roman

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


This was one of the first things I did. Snow Leopard's version of XCode is installed on my machine.
R
Raihan Alam

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


V
Vestel

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


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.
A
AlexeyKa

If you use Percona Mysql server

$ yum install Percona-Server-devel-55

$ gem install mysql


a
austin
yum -y install gcc mysql-devel ruby-devel rubygems
gem install mysql2

M
Mayur Kambariya

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

After That just install bundle or bundle install