我对MySQL gem安装错误感到有点困惑。由于mysql从5.0.xx更新到5.1.39,我已经卸载了mysqlgem,现在我无法正确安装它。
我已经将mysql-2.8.1.gem下载到服务器上,因为它位于代理之后。我看过很多教程,其中告诉我必须包含mysql_config才能消除这个错误,但这对我没有帮助。
操作系统是Red Hat Enterprise Linux Server 5.3版(Tikanga)。
[my@server ~]$ sudo gem install mysql-2.8.1.gem --no-rdoc --no-ri -- --with-mysql-config=/usr/bin/mysql_config
Building native extensions. This could take a while...
ERROR: Error installing mysql-2.8.1.gem:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile
make
gcc -I. -I. -I/usr/local/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_H -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX -fPIC -g -O2 -c mysql.c
gcc -shared -o mysql_api.so mysql.o -L. -L/usr/local/lib -Wl,-R/usr/local/lib -L. -rdynamic -Wl,-export-dynamic -rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lssl -lcrypto -lrt -ldl -lcrypt -lm -lc
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld returned 1 exit status
make: *** [mysql_api.so] Error 1
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
有什么建议吗?
从错误中可以看出,您的MySQL版本似乎与您正在使用的gem版本不兼容。
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
如果你安装了多个MySQL版本,那么gem可能会选择一个旧版本。您应该使用MySQL gem文档来验证您正在使用的verison,而MySQL版本是必需的。
我建议您使用mysql2-gem。如果你使用的是ruby 1.8系列,你应该使用gem版本0.2.11或0.2.13,或者如果你使用ruby 1.9系列,我建议你使用gem 0.3.7。0.3.X由于某些原因在ruby 1.8上不起作用。
它应该像符咒一样工作。:)