MySQL 安装:错误:无法构建 gem 本机扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2167598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL Install: ERROR: Failed to build gem native extension
提问by Kezzer
I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql
and I receive the following:
我正在尝试将 MySQL 安装到最新版本,因为某些安装在某处出现错误。我运行命令gem install mysql
并收到以下信息:
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 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
构建原生扩展。这可能需要一段时间... 错误:安装 mysql 时出错:错误:无法构建 gem 本机扩展。
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb extconf.rb:4:警告:不安全的世界可写目录 /usr/bin 在 PATH,模式 040777 extconf.rb:4:警告:PATH 中不安全的世界可写目录 /usr/bin,模式 040777 extconf.rb:7:警告:PATH 中不安全的世界可写目录 /usr/bin,模式 040777 mkmf.rb 在 /System 找不到 ruby 的头文件/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem 文件将保留安装在 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 中以供检查。结果记录到 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I've searched, and tried a whole host of things, from installing specific versions to trying to reinstall ruby without any luck.
我已经搜索并尝试了很多事情,从安装特定版本到尝试重新安装 ruby 没有任何运气。
Any ideas where I may be going wrong?
我可能会出错的任何想法?
I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql
and I receive the following:
我正在尝试将 MySQL 安装到最新版本,因为某些安装在某处出现错误。我运行命令gem install mysql
并收到以下信息:
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 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
构建原生扩展。这可能需要一段时间... 错误:安装 mysql 时出错:错误:无法构建 gem 本机扩展。
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb extconf.rb:4:警告:不安全的世界可写目录 /usr/bin 在 PATH,模式 040777 extconf.rb:4:警告:PATH 中不安全的世界可写目录 /usr/bin,模式 040777 extconf.rb:7:警告:PATH 中不安全的世界可写目录 /usr/bin,模式 040777 mkmf.rb 在 /System 找不到 ruby 的头文件/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem 文件将保留安装在 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 中以供检查。结果记录到 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I've searched, and tried a whole host of things, from installing specific versions to trying to reinstall ruby without any luck.
我已经搜索并尝试了很多事情,从安装特定版本到尝试重新安装 ruby 没有任何运气。
Any ideas where I may be going wrong?
我可能会出错的任何想法?
EDIT: I installed XCode off my Snow Leopard DVD and the error just changed slightly to the following:
编辑:我从我的雪豹 DVD 上安装了 XCode,错误只是稍微更改为以下内容:
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 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:4: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:7: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 extconf.rb:17: warning: Insecure world writable dir /usr/bin in PATH, mode 040777 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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
构建原生扩展。这可能需要一段时间... 错误:安装 mysql 时出错:错误:无法构建 gem 本机扩展。
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb extconf.rb:4:警告:不安全的世界可写目录 /usr/bin 在 PATH,模式 040777 extconf.rb:4:警告:PATH 中不安全的世界可写目录 /usr/bin,模式 040777 extconf.rb:7:警告:PATH 中不安全的世界可写目录 /usr/bin,模式 040777 extconf.rb:17:警告:不安全的世界可写目录 /usr /bin in PATH, mode 040777 检查 -lmysqlclient 中的 mysql_query() ... 不检查 -lm 中的 main() ... 是检查 -lmysqlclient 中的 mysql_query() ... 不检查 main() - lz...是在-lmysqlclient中检查mysql_query()...在-lsocket中没有检查main()...在-lmysqlclient中没有检查mysql_query()...在-lnsl中没有检查main()。 .. 不检查 -lmysqlclient 中的 mysql_query() ... 不检查 -lmygcc 中的 main() ...不检查 -lmysqlclient 中的 mysql_query() ... 不 * extconf.rb 失败 *由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。检查 mkmf.log 文件以获取更多详细信息。您可能需要配置选项。
提供的配置选项: --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=/System/Library/Frameworks/Ruby.framework/Versions/1。
Gem 文件将保留安装在 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1 中以供检查。结果记录到 /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
doing "which mysql" on the command line returns nothing, which means it's not recognizing it. I also installed the MySQL system preferences option, and I can't stop MySQL from running. Now I'm completely stuck as what to do!
在命令行上执行“which mysql”不会返回任何内容,这意味着它无法识别它。我还安装了 MySQL 系统首选项选项,我无法阻止 MySQL 运行。现在我完全不知道该怎么做!
EDIT EDIT
编辑 编辑
I've just completely reinstalled MySQL using this guide http://hivelogic.com/articles/installing-mysql-on-mac-os-x
我刚刚使用本指南完全重新安装了 MySQL http://hivelogic.com/articles/installing-mysql-on-mac-os-x
Unfortunately this didn't work either, I still receive the same errors. I can't even do mysql -uroot at the command line, I get the error of:
不幸的是,这也不起作用,我仍然收到相同的错误。我什至无法在命令行执行 mysql -uroot,我收到以下错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ERROR 2002 (HY000): 无法通过 socket '/tmp/mysql.sock' 连接到本地 MySQL 服务器 (2)
So I think I've tried everything.
所以我想我已经尝试了一切。
**SOLVED*
**解决了*
Sorry guys, the reason for this not working was because of the MySQL paths. I've blogged on it here: http://www.kieransenior.co.uk/2010/02/mysql-cant-connect-using-ruby-on-rails-mac-os-x-snow-leopard/
对不起,这不起作用的原因是因为 MySQL 路径。我在这里写了博客:http: //www.kieransenior.co.uk/2010/02/mysql-cant-connect-using-ruby-on-rails-mac-os-x-snow-leopard/
采纳答案by Trevoke
Installing the mysql gem on OSX
in a terminal.. First do a ‘locate mysql_config' and then replace the path in the following command with where that file is.
在终端中.. 首先执行“定位 mysql_config” ,然后将以下命令中的路径替换为该文件所在的位置。
$ sudo gem install mysql -- —–with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while…
Successfully installed mysql-2.7
1 gem installed
回答by cartoonist
On Debian (or Ubuntu) systems, just install libmysqlclient-dev package using:
在 Debian(或 Ubuntu)系统上,只需使用以下命令安装 libmysqlclient-dev 包:
sudo apt-get install libmysqlclient-dev
and then:
进而:
gem install mysql
It will be installed without any error.
它将被安装而不会出现任何错误。
回答by Aurril
First of all you need to differentiate between the MySQL as Server, MySQL as Client and the Ruby bindings to MySQL.
首先,您需要区分 MySQL 作为服务器、MySQL 作为客户端和 Ruby 绑定到 MySQL。
I'm not familiar with Mac, but for *nix OS you need to install MySQL through your package manager. To get the Ruby bindings installed with
我不熟悉 Mac,但对于 *nix 操作系统,您需要通过包管理器安装 MySQL。安装 Ruby 绑定
gem install mysql
you need the development headers of ruby (in Ubuntu it is the package ruby-dev) and the development headers of the MySQL-Client (currently libmysqlclient16-dev
in Ubuntu). I don't know if they are named different on Mac, but after you got those installed the Ruby bindings should install without any error.
你需要 ruby 的开发头文件(在 Ubuntu 中它是包 ruby-dev)和 MySQL-Client 的开发头文件(目前libmysqlclient16-dev
在 Ubuntu 中)。我不知道它们在 Mac 上的命名是否不同,但是在安装了它们之后,Ruby 绑定应该会安装而不会出现任何错误。
回答by Guy Saban
回答by downrightmike
on OSX mountain Lion: If you have brew
installed, then brew install mysql
and follow the instructions
on creating a test database with mysql on your machine.
You don't have to go all the way through, I didn't need to
After I did that I was able to bundle install and rake.
在 OSX Mountain Lion 上:如果您已brew
安装,请brew install mysql
按照instructions
在您的机器上使用 mysql 创建测试数据库的说明进行操作。你不必一路走完,我不需要在我完成之后我能够捆绑安装和耙。
回答by rahul patil
In order to resolve
为了解决
Gem::Ext::BuildError: ERROR: Failed to build gem native extension error for mysql2,
I think libmysql-rubygot changed with ruby-mysql
Gem::Ext::BuildError: 错误:无法为 mysql2 构建 gem 本机扩展错误,
我认为libmysql-ruby被ruby-mysql改变了
Simply try with following commands,
只需尝试使用以下命令,
sudo apt-get install ruby-mysql
sudo apt-get install ruby-mysql
& then
& 然后
sudo apt-get install libmysqlclient-dev
回答by Promise Preston
I had a similar experience, so here are the things that I tried
我有类似的经历,所以这里是我尝试过的事情
Firstly, I tried to install mysql's required packages by running the command below in my terminal
首先,我尝试通过在终端中运行以下命令来安装 mysql 所需的软件包
sudo apt-get install build-essential libmysqlclient-dev
Secondly, I tried updating rubygems on my system by running the command below in my terminal
其次,我尝试通过在终端中运行以下命令来更新系统上的 rubygems
sudo gem update --system
But I was still experiencing the same issue. After much research I realized that I was using an almost out-of-date version of the mysql gem. I simply needed to use the mysql2gem (mysql2 gem)and not the mysqlgem, so I fixed it by running the command below in my terminal
但我仍然遇到同样的问题。经过大量研究,我意识到我使用的是一个几乎过时的 mysql gem 版本。我只需要使用mysql2gem ( mysql2 gem) 而不是mysqlgem,所以我通过在终端中运行下面的命令来修复它
gem install mysql2
This worked fine for me. Before running the last command, ensure that you've ran the first and second commands to be sure that everything is fine on your system.
这对我来说很好。在运行最后一条命令之前,请确保您已经运行了第一条和第二条命令,以确保系统上一切正常。
That's all.
就这样。
I hope this helps
我希望这有帮助
回答by Richard Burton
I had also forgotten to actually installMySQL in the first place. Following this guide helped a lot.
我还忘记了首先实际安装MySQL。遵循本指南有很大帮助。
http://www.djangoapp.com/blog/2011/07/24/installation-of-mysql-server-on-mac-os-x-lion/
http://www.djangoapp.com/blog/2011/07/24/installation-of-mysql-server-on-mac-os-x-lion/
As well as adding these lines to my .profile:
以及将这些行添加到我的 .profile 中:
export PATH="/usr/local/mysql/bin:$PATH"
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
回答by roman
you can try to reinstall the latest version of xcode / dev. tools for snow leopard - this should fix your errors
您可以尝试重新安装最新版本的 xcode/dev。雪豹的工具 - 这应该可以解决你的错误
回答by Raihan Alam
if you are installing from source here is a tutorial.would be happy if it helps http://raihan90.blogspot.com/2009/03/mysql-step-by-step-hacking-into-mysql.html
如果您从源代码安装这里是一个教程。如果它有帮助,我会很高兴http://raihan90.blogspot.com/2009/03/mysql-step-by-step-hacking-into-mysql.html