无法在Mac OS X上安装MySQL

时间:2010-01-06 17:15:54

标签: mysql ruby-on-rails macos install gem

我遇到了这个问题中描述的确切问题:MYSQL Installation Troubles。不幸的是,没有一个答案对我有帮助(而且它已经关闭)。

我尝试学习Ruby on Rails并且不让MySQL工作(因此它与编程相关)。

我输入了rake db:create并得到了:

!!!The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql

(See full trace by running task with --trace)
HD-Auckland:shoutbox max$ gem install mysql
WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
      /usr/bin aren't both writable.
WARNING:  You don't have /Users/max/.gem/ruby/1.8/bin in your PATH,
      gem executables will not run.
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
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.

Gem files will remain installed in /Users/max/.gem/ruby/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /Users/max/.gem/ruby/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

因为它告诉我我尝试了sudo gem install mysql并得到了:

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

/opt/local/bin/ruby extconf.rb
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=/opt/local/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 /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

我也试过这个命令sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config并得到了同样的错误!

我该怎么办?我只想将我的数据库迁移到MySQL服务器!

感谢您的帮助,Mexx

更新

嘿,大家好的回应!是的我在Snow Leopard上。 我从这里http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg下载了mysql并安装了它。 然后我按照Hivelogic的指南安装了mysql。

我现在输入:sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_configsudo gem istall mysqlsudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

我会得到:

Building native extensions.  This could take a while...
fotoSuccessfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...

No definition for next_result

No definition for field_name

No definition for field_table

No definition for field_def

No definition for field_type

No definition for field_length

No definition for field_max_length

No definition for field_flags

No definition for field_decimals

No definition for time_inspect

No definition for time_to_s

No definition for time_get_year

No definition for time_get_month

No definition for time_get_day

No definition for time_get_hour

No definition for time_get_minute

No definition for time_get_second

No definition for time_get_neg

No definition for time_get_second_part

No definition for time_set_year

No definition for time_set_month

No definition for time_set_day

No definition for time_set_hour

No definition for time_set_minute

No definition for time_set_second

No definition for time_set_neg

No definition for time_set_second_part

No definition for time_equal

No definition for error_errno

No definition for error_sqlstate
Installing RDoc documentation for mysql-2.8.1...

No definition for next_result

No definition for field_name

No definition for field_table

No definition for field_def

No definition for field_type

No definition for field_length

No definition for field_max_length

No definition for field_flags

No definition for field_decimals

No definition for time_inspect

No definition for time_to_s

No definition for time_get_year

No definition for time_get_month

No definition for time_get_day

No definition for time_get_hour

No definition for time_get_minute

No definition for time_get_second

No definition for time_get_neg

No definition for time_get_second_part

No definition for time_set_year

No definition for time_set_month

No definition for time_set_day

No definition for time_set_hour

No definition for time_set_minute

No definition for time_set_second

No definition for time_set_neg

No definition for time_set_second_part

No definition for time_equal

No definition for error_errno

No definition for error_sqlstate

执行rake db:create最终将会:

(in /Users/max/rails/shoutbox)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql

(See full trace by running task with --trace)

7 个答案:

答案 0 :(得分:7)

出于某种原因(可能因为我使用的是rubygems 1.3.7或安装mysql-2.8.1)

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

对我不起作用所以看了gems / mysql-2.8.1 / ext / mysql_api / extconf.rb我发现extconf.rb在PATH中查找mysql_config所以我试过

export PATH=$PATH:/usr/local/mysql/bin
sudo gem install mysql

并完成了工作

答案 1 :(得分:1)

你是雪豹吗?您必须使用x64标头执行C依赖项编译,请尝试:

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

答案 2 :(得分:1)

我自己遇到了MySQL gem的问题,这些是我实际收藏的唯一2个链接,所以其中一个实际上对我有效。以为我会分享。

  1. http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard
  2. http://rapd.wordpress.com/2007/05/17/battle-against-ror-gem-install-mysql/
  3. 第二个有点旧,所以不确定它是否仍然适用。

答案 3 :(得分:0)

要在OS X上安装MySQL gem,您需要安装安装盘上的XCode开发人员工具。您也可以从http://developer.apple.com下载它们。

答案 4 :(得分:0)

我只是使用此命令结束了该问题:

 sudo env ARCHFLAGS="-arch i386" gem install --no-rdoc --no-ri mysql -v 2.8.1 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

确实我需要在我的mac OS X Leopard 10.5.8上安装mysql gem版本2.8.1,从dmg文件运行mysql-5.6.2-m5-osx10.5-x86。我有一个问题,它无法找到库,我做了一些操作,然后由于权限无法安装。我发现了那个命令,添加了我需要的版本并将架构更改为与我的mysql安装相对应的版本。

所以,如果有人还想安装那个版本:)让我们试试吧!但是我们可能不是很多安装这个,而不是Leopard!

答案 5 :(得分:0)

使用的正确宝石是mysql2

答案 6 :(得分:0)

我遇到了同样的问题。我解决了先安装适配器的问题:

gem install activerecord-mysql2-adapter

然后,使用

安装mysql2 gem
sudo gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config