Ruby Gem安装mysql报错( ruby版本2.4.1)

  • A+
所属分类:Rails ruby

Ruby Gem安装mysql报错( ruby版本2.4.1)

错误信息

执行gem install mysql后,出现如下报错:

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

    current directory: /home/xxx/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql-2.9.1/ext/mysql_api
/home/xxx/.rbenv/versions/2.4.1/bin/ruby -r ./siteconf20180722-25370-qcswvf.rb extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile

current directory: /home/xxx/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql-2.9.1/ext/mysql_api
make "DESTDIR=" clean

current directory: /home/xxx/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql-2.9.1/ext/mysql_api
make "DESTDIR="
compiling mysql.c
mysql.c: In function ‘stmt_bind_result’:
mysql.c:1320: error: ‘rb_cFixnum’ undeclared (first use in this function)
mysql.c:1320: error: (Each undeclared identifier is reported only once
mysql.c:1320: error: for each function it appears in.)
At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign"
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand"
cc1: warning: unrecognized command line option "-Wno-parentheses-equality"
cc1: warning: unrecognized command line option "-Wno-tautological-compare"
make: *** [mysql.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/xxx/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql-2.9.1 for inspection.
Results logged to /home/xxx/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/mysql-2.9.1/gem_make.out

解决办法

方法一:

由于myslq gem版本没有更新,不支持ruby2.4及以后版本,所以可以把ruby切换到2.3的版本。

方法二:

不使用mysql gem,使用更高效的驱动mysql2 gem。

gem install mysql2
百分购

发表评论

您必须才能发表评论!