bundle install problem: mysql.h is missing

2019-01-16 07:38发布

in my mac OSX 10.6 32 bit, I can install mysql2 gem quite easily, but not in mini mac 10.6 64bit server.

I have installed MySQL 5.5.11 in troublesome server, while in my home mac MySQL 5.5.0.m2 Somehow when I run bundle install, in server it tries to install mysql2.0.3.2 while in home mysql2.0.2.6

Please don't tell me to

env ARCHFLAGS="-arch x86_64" sudo gem install mysql2 --version '= 0.2.6' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I tried that, doesn't work.

Included /usr/local/mysql/bin in $PATH does not help as well.

Error code:

    Installing mysql2 (0.3.2) with native extensions /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
-----
mysql.h is missing.  please check your installation of mysql and try again.
-----
*** 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=/Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2 for inspection.
Results logged to /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/ext/mysql2/gem_make.out
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:511:in `block in build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `each'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:159:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/source.rb:96:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:55:in `block in run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:44:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:8:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/cli.rb:225:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/bin/bundle:13:in `<top (required)>'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `load'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `<main>'

12条回答
冷血范
2楼-- · 2019-01-16 08:08

Ok guys for me the solution was:

$ sudo brew install mysql

$ sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-include=/usr/local/mysql/include

source: http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard

OR :

$sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-include=/usr/local/mysql/include

If your mysql version is 64Bits

After that i had a lot of problems because if i want to create the database:

$: bundle exec rake db:reset

i was receiving this error:

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Users/workdreamer/Sites/cavortify/implementation/cavortify/mysql/ruby/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Users/workdreamer/Sites/cavortify/implementation/cavortify/mysql/ruby/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
  Expected in: flat namespace

The solution is: On your gemfile add: gem "ruby-mysql"

Ok, one day and a half to find the solution.

Have a nice day!

查看更多
地球回转人心会变
3楼-- · 2019-01-16 08:11

For mariadb:

sudo apt-get install libmariadbclient18 libmariadbclient-dev

Then

gem install mysql2

could be successfully installed.

查看更多
神经病院院长
4楼-- · 2019-01-16 08:15

This worked for me on my Mac OSX Lion:

sudo env ARCHFLAGS="-I/usr/local/include/mysql/mysql  -pipe -fPIC    -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/lib/mysql/mysql --with-mysql-include=/usr/local/include/mysql/mysql --with-mysql-config=/usr/local/bin/mysql_config

This blog answered it.

查看更多
Melony?
5楼-- · 2019-01-16 08:17

My problem was the result of first installing MySql via the downloadable binary. It was originally installed at version 5.5.28. I then attempted to install via homebrew. Brew installed version 5.6.x. HOWEVER in the process of installing via homebrew, the symlink for /usr/local/mysql was still pointed to 5.5.28.

Update your symlink to whichever version was installed via homebrew.

ex: /usr/local/mysql -> /usr/local/Cellar/mysql/5.6.13/

This could be just part of the solution.

查看更多
爷的心禁止访问
6楼-- · 2019-01-16 08:19

I tried all the solutions posted here, but was not lucky. I reinstalled mysql with homebrew a couple of times and still no luck. Then I came across a blog post with a solution.

I edited the mysql_config file in /usr/local/Cellar/mysql/5.6.12/bin and removed the W-compiler options -Wno-null-conversion and -Wno-unused-private-field for cflags and cxxflags.

This solved the problem with gem install mysql2 and bundle install

Reference: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-16 08:20

Verify that gcc is installed. If it isn't, you will get that same error message.

You can check the results/log file it mentions for more clues as to the cause.

查看更多
登录 后发表回答