尝试了很多建议,如何安装mysql2 gem?

时间:2011-12-20 16:23:37

标签: mysql ruby-on-rails ubuntu ubuntu-11.04

我正在尝试在rails应用程序上的ruby上安装mysql2 gem。我目前正在运行Ubuntu 11.04,这是我运行sudo gem install mysql2bundle install时出现的错误:

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

/usr/bin/ruby1.8 extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile

make
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H    -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing  -g -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -Wall -funroll-loops  -c client.c
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H    -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing  -g -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -Wall -funroll-loops  -c mysql2_ext.c
./client.h:16:1: warning: ‘rb_thread_blocking_region’ defined but not used
gcc -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H    -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing  -g -fPIC -fno-strict-aliasing -g -g -O2  -fPIC  -Wall -funroll-loops  -c result.c
gcc -shared -o mysql2.so client.o mysql2_ext.o result.o -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -Wl,-rpath,/usr/lib/x86_64-linux-gnu    -lruby1.8 -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r -lpthread -lz -lm -lrt -ldl  -lpthread -lrt -ldl -lcrypt -lm   -lc
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make: *** [mysql2.so] Error 1


Gem files will remain installed in /var/lib/gems/1.8/gems/mysql2-0.3.11 for inspection.
Results logged to /var/lib/gems/1.8/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

我尝试使用mysql_config安装,我已经安装了libmysqlclient-dev和libmysql-ruby库,我尝试卸载并重新安装mysql。它都不起作用。我能够成功安装mysql gem而不是mysql2。

我正在运行ruby1.8和Rails 2.3.5。任何人都可以帮助我吗?

3 个答案:

答案 0 :(得分:4)

试试这个:

sudo apt-get install libmysql-ruby

sudo apt-get install libmysqlclient-dev

sudo gem install mysql2

答案 1 :(得分:1)

看看这个blog和其他人喜欢它。但最终,我建议从11.04升级到11.10。我在运行11.04时遇到了许多奇怪的错误,因为转到11.10,一切都更加稳定。

答案 2 :(得分:1)

如果您正在运行CentOS / Redhat,请尝试安装以下软件包(使用yum):

MySQL-devel-5.5.22-1.el6.x86_64
MySQL-shared-5.5.22-1.el6.x86_64
MySQL-shared-compat-5.5.22-2.el6.x86_64