2012-04-11 15 views
6

Estoy tratando de instalar mysql2 en el servidor. así que mi primera pista de mala suerte era la siguienteError al instalar mysql2

gem install mysql2 

la salida

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

/usr/bin/ruby1.8 extconf.rb 
checking for rb_thread_blocking_region()... no 
checking for rb_wait_for_single_fd()... 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... yes 
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=/usr/bin/ruby1.8 
    --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 /home/aaalsubaie/.gems/gems/mysql2-0.3.11 for inspection. 
Results logged to /home/aaalsubaie/.gems/gems/mysql2-0.3.11/ext/mysql2/gem_make.out 

este no es el final de la historia

después de ejecutar

[ps89405]$ mysql --help | grep Default -A 1 
Default options are read from the following files in the given order: 
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 

Probé

gem install mysql2 -- --with-mysql-config=~/.my.cnf --ruby=/usr/bin/ruby1.8 

y

gem install mysql2 -- --with-mysql-config=/usr/etc/my.cnf --ruby=/usr/bin/ruby1.8 

y

gem install mysql2 -- --with-mysql-config=/etc/my.cnf --ruby=/usr/bin/ruby1.8 

sin suerte el mismo error.

I No corra RVM

y mi joya env es

RubyGems Environment: 
    - RUBYGEMS VERSION: 1.3.7 
    - RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux] 
    - INSTALLATION DIRECTORY: /home/aaalsubaie/.gems/ 
    - RUBY EXECUTABLE: /usr/bin/ruby1.8 
    - EXECUTABLE DIRECTORY: /home/aaalsubaie/.gems/bin 
    - RUBYGEMS PLATFORMS: 
    - ruby 
    - x86_64-linux 
    - GEM PATHS: 
    - /home/aaalsubaie/.gems/ 
    - /usr/lib/ruby/gems/1.8 
    - GEM CONFIGURATION: 
    - :update_sources => true 
    - :verbose => true 
    - :benchmark => false 
    - :backtrace => false 
    - :bulk_threshold => 1000 
    - REMOTE SOURCES: 
    - http://rubygems.org/ 

este es mi segundo día en fila tratando de desplegar mi primera aplicación rieles sin suerte que a pesar de que será mucho más fácil.

actualización:

ahora el comando está trabajando y la instalación de mysql2 joya gracias a Yanhao

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

tengo nuevo tema ahora con la gema mysql2 cuando corro

bundle exec rails console 

llegué

/home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': no such file to load -- mysql2/mysql2 (LoadError) 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/mysql2-0.3.11/lib/mysql2.rb:9 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require' 
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in `require' 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/config/application.rb:7 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/railties-3.2.1/lib/rails/commands.rb:39:in `require' 
from /home/aaalsubaie/ajhezaty.com/releases/20120411095320/vendor/bundle/ruby/1.8/gems/railties-3.2.1/lib/rails/commands.rb:39 
from script/rails:6:in `require' 
from script/rails:6 

Respuesta

3

El comando debe desea:

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

opción "con-MySQL-config" se refiere a la función "mysql_config", en lugar del archivo de configuración.

Y será mejor que el archivo mkmf.log.

+1

/usr/local/mysql/bin/¡no existe en mi servidor! Tampoco entiendo su última línea. – aaalsubaie

+0

gracias funciona después de instalar la biblioteca dev. Tengo un nuevo problema ahora puede leer mi actualización sobre la pregunta anterior. – aaalsubaie

+0

¿Hay otro 'paquete de instalación'? – Reactormonk

14

Esto puede no ser directamente relevantes para usted, pero yo enfrentado el mismo problema, y ​​creo que mi respuesta puede ayudar a otros con este tema:

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

que trabajó para mí.

+0

gracias, tiempo guardado) – ajahongir

+0

gracias me salvaste el tiempo :) –

+0

+1. Gracias, esto ayudó ... –

4

Si está en una Mac, instale MySQL con Homebrew brew install mysql y eso le permitirá instalar la gema después.

0

En primer lugar hay que ejecutar este comando:

sudo apt-get install libmysqlclient-dev 

y luego se puede ejecutar este:

gem install mysql2 

debe ser un trabajo ..

0

sudo apt-get instalar libmysqlclient-dev el sistema instalará otras dos lib: mysql-common libmysqlclient16

0

"bundle exec rails console" se ejecuta contra el Gemfile del paquete, pero instaló mysql2 con rubygems. Tendrá que ejecutar:

gem uninstall mysql2    # uninstall mysql2 from system 
bundle exec gem uninstall mysql2 # uninstall mysql2 from bundler 
bundle config build.mysql2 --with-mysql-config=/usr/bin/mysql_config # set build option for mysql2 gem 
bundle install     # reinstall mysql2 
bundle exec rails console   # start rails console using the rails exec installed via bundler 

Nota adicional: Si está utilizando pasajeros y que acaba de actualizar su versión de Ruby, asegúrese de volver a instalar pasajeros y actualizar su httpd.conf con el fin de iniciar el servidor con éxito.