在Mac OS X上无法安装MySQL

5
我遇到了与这个问题描述完全相同的问题:MYSQL安装问题。不幸的是,没有一个答案对我有帮助(并且它已经关闭了)。
我试着学习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_config 或者 sudo gem istall mysql 或者 sudo 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)

只是想澄清一下,你是如何安装mysql的?是从mysql官网的二进制文件、fink、ports、brew等安装的吗? - apod
sudo port install mysql5 +server rb-mysql我觉得我已经运行了这个命令,但是当你问的时候我不确定,所以我再次运行它,现在正在下载 :/ 抱歉,希望没有浪费你们的时间。下载完成后我会在这里更新。 - Max
通过macports进行安装时,我遇到了以下错误:错误:目标org.macports.configure返回:lipo:无法打开输入文件:/opt/local/lib/libz.dylib(没有那个文件或目录) 错误:处理过程中遇到状态1。 - Max
1
你可以按照Hivelogic的指南安装mysql。 http://hivelogic.com/articles/compiling-mysql-on-snow-leopard - apod
7个回答

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
谢谢。在Snow Leopard上完美运行! - JP Richardson

1

你使用的是Snow Leopard操作系统吗?你需要使用x64头文件编译C依赖项,尝试执行以下命令:

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

你不必这样做。我按照这些说明从源代码安装了64位Snow Leopard MySQL,并且它可以正常工作:http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/ - John Topley

1

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上的安装量更少!


0

我曾经遇到过同样的问题。我解决了这个问题,首先安装了适配器:

gem install activerecord-mysql2-adapter

然后,使用以下命令安装mysql2 gem

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

0

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


0

正确的 gem 是 mysql2


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接