我有一些问题时,试图安装mysql2宝石为Rails。当我试图通过运行bundle install或gem install mysql2来安装它时,它会给我以下错误:

安装mysql2错误:错误:未能建立gem本地扩展。

我如何解决这个问题并成功安装mysql2?


当前回答

Libmysql-ruby已经被淘汰和取代。新命令:

 sudo apt-get install ruby-mysql libmysqlclient-dev

其他回答

windows用户: 你可以设置lib和mysql的路径,例如,如果你使用xampp,你可以这样:

gem install mysql2 -- '--with-mysql-lib="C:\xampp\mysql\lib" --withmysql-include="C:\xampp\mysql\include"'

我有几台电脑,32位和64位处理器,它们运行在Ubuntu Linux, Maverick(10.10)发行版上。

我也有同样的问题,对我来说 安装libmysqlclient-dev 完成了任务!!

这解决了我在Windows中的问题:

subst X: "C:\Program files\MySQL\MySQL Server 5.5" 
gem install mysql2 -v 0.x.x --platform=ruby -- --with-mysql-dir=X: --with-mysql-lib=X:\lib\opt 
subst X: /D

I got the gem built on Mac OS X 10.6.6 by 1) Ensuring the Developer tools package is installed 2) Downloading the current MySQL package (5.5.8 in my case) from Source 3) Installing the cmake tool from cmake.org 4) Following the instructions in section 2.11 of INSTALL-SOURCE from the mysql distribution files 5) sudo gem install mysql2 -- --srcdir=/usr/local/mysql/include The gem built successfully, but there are two errors in the documentation that rdoc and ri complain about. But now when I try to require 'mysql2' I get a

LoadError: no such file to load -- mysql2/mysql2

我希望我得到的错误是libmysqlclient.16。Dylib无法找到,因为我们在另一篇文章中找到了(搜索install_name_tool)。

我的$PATH有/usr/local/mysql在里面(这是我的源代码和构建文件所在的位置),所以我有点难住了。如果有人有什么想法,我会在睡了几个小时后再来看看。

从[这里][1]下载连接器C文件。(https://downloads.mysql.com/archives/c-c/) 将文件解压到一个位置,如C:\ror\mysqlC\mysql-connector-c-6.1.11-winx64\lib 使用这个模板

install mysql2——'——with-mysql-lib="$lib_location"——with-mysql-include="$include_location"'

我的安装位置是lib_location -> C:\ror\mysqlC\mysql-connector-c-6.1.11-winx64\lib

——with-mysql-lib="C:\ror\mysqlC\mysql-connector-c-6.1.11-winx64\lib"——with-mysql-include="C:\ror\mysqlC\mysql-connector-c-6.1.11-winx64\include"'