Pregunta

Cuando intento instalar la gema mysql2, falla sin errores aparentes. ¿Alguien sabe qué hacer para evitar este mysql2 por lo instala?

$ sudo gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
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/mysql2-0.2.6 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
¿Fue útil?

Solución

Hay que tener 64 bits MySQL instalado en su máquina, además de las herramientas de construcción que se obtiene al instalar Xcode.

Otros consejos

Ubuntu:

sudo apt-get install libmysqlclient-dev  #(mysql development headers)
sudo gem install mysql2 -- --with-mysql-dir=/etc/mysql/

Eso es todo!

Resultados:

Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Result not known
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Result not known
Enclosing class/module 'mMysql2' for class Client not known

Se necesitan las cabeceras de desarrollo de MySQL para mysql2 para compilar correctamente. Esto es necesario, porque gran parte de la funcionalidad está escrito en C y posteriormente unidos contra MySQL.

Una solución consiste en cualquiera de los puntos del instalador joya a su carpeta de instalación de MySQL explícitamente como tal

gem install mysql2 -- --with-mysql-dir=/usr/local/mysql
# or where ever you installed your mysql server to

o mediante la instalación de un servidor MySQL en una ubicación conocida (por ejemplo, mediante el uso de homebrew .) Y después de instalar la gema

# install the mysql server locally
brew install mysql
# install the gem
gem install mysql2

Ambos enfoques requieren que tenga instalado XCode tener el compilador GCC necesario.

Con instalados Brew y MySQL, que utiliza lo siguiente para instalar la gema mysql2

gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.5.10/bin/mysql_config

Si está utilizando Bündler, se puede decir sobre este bundler con el comando:

bundle config build.mysql2 --with-mysql-config=/usr/local//Cellar/mysql/5.5.10/bin/mysql_config

Como se documenta aquí: http://gembundler.com/man/bundle-config. 1.html

en Mac OS X Mountain Lion, por debajo de comando funcionó para mí:

gem install mysql2 -- --srcdir=/usr/local/mysql/include

Ubuntu 15.04:

sudo apt-get install libmysqlclient-dev
sudo gem install mysql2

Ubuntu-16.04:

sudo apt-get install ruby-mysql2
sudo gem install mysql2

Salida:

Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.19
Parsing documentation for mysql2-0.3.19
Installing ri documentation for mysql2-0.3.19
Done installing documentation for mysql2 after 0 seconds
1 gem installed

Es posible que desee comprobar este hilo en el sitio web de MySQL: http: / /forums.mysql.com/read.php?116,178217,178217 , en particular la respuesta de Scott Derrick: http://forums.mysql.com/read.php?116,178217,189357#msg-189357

Para ser más específico, trate de usar

sudo gem install mysql2 -- --with-mysql-dir=/usr/local/mysql

Espero que ayude.

Me buscó en 2 días el valor de Internet y de desbordamiento de pila, y no fue hasta que encontré este enlace y luego empezar a trabajar a través de este billete para mysql2 de que realmente resuelva el problema.

Con mi configuración (como se explica en el billete), el compilador cambia de -Wno-null-conversión--Wno sin usar-privada-campo se rompería y me da un error que no era exactamente correcto, que era:

mysql.h is missing. please check your installation of mysql and try again

supongo que si escribe rvm use ruby-2.1.0@rails4.0 --create en que directorio, bundle install funciona.

Me resuelto esto por ser específico sobre dónde están los directorios, sin necesidad de instalar nada , la cerveza o macports o lo que sea, simplemente especificando dónde están las cosas (una sola cosa: el rubí en mi mac se instaló con RVM, no estoy usando la opción por defecto que viene con OS X):

añadir a su gem install mysql2 las banderas abajo

  • --srcdir="..." - la incluye
  • --with-mysql-dir="..." - el directorio mysql
  • --with-mysql-config="..." - el archivo mysql_config

como esto gem install mysql2 --srcdir=/usr/local/mysql/include/ --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

En Centos 6.x (7 debería funcionar) con SCL (colección de software) rh-mysql:

scl enable rh-mysql56 bash
gem install mysql2 -v '0.4.5' -- --with-mysql-include=/opt/rh/rh-mysql56/root/usr/include --with-mysql-lib=/opt/rh/rh-mysql56/root/usr/lib64
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top