在Mac OS上安装mysql2

时间:2013-07-02 17:08:46

标签: ruby rubygems ruby-on-rails-4 mysql2 ruby-2.0

我已经安装了Ruby 2,Rails 4和MySQL(带有自制软件)。

我尝试安装gem“mysql2”,但我收到了这条消息:

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

/usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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
--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/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-mysql-config
--without-mysql-config


Gem files will remain installed in /usr/local/rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.11 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

你能帮助我吗?

2 个答案:

答案 0 :(得分:1)

由于某种原因,通过自制软件安装mysql被破坏了。您必须手动编辑mysql_config

自制软件的mysql_config文件保留在/usr/local/Cellar/mysql/5.6.12/bin, 在第120行左右用sudo打开它,找到以下行:

cflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!

这两行中的远程-Wno-null-conversion -Wno-unused-private-filed如下:

cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!

保存文件并再次执行brew install mysql,它应该可以正常工作。

检查this blog post

答案 1 :(得分:1)

检查所安装的Rails和mysql版本的兼容性。 和我一起,我从Mysql 8.0开始使用Rails 4.1.15,但它不起作用,并且遇到类似的错误。 然后我安装了

brew install mysql56

在此卸载mysql之前,如果您已经使用-安装了一个

brew uninstall mysql
brew cleanup

现在通过指定要用作mysql的数据库来创建一个新的Rails项目

rails new <PROJECT_NAME> -d mysql

这将创建一个具有兼容mysql的新Rails 4项目 之后,您可以随时配置database.yml文件以获取更多详细信息