mysql2 Ruby Gem 在 Ubuntu 20.04 安装失败。

6

有人知道是什么原因导致这个问题,以及我该如何解决吗? 我正在为我的项目安装一个Ruby gem,这是一个运行在Rails 3上的旧项目,但我在Ubuntu 20.04上运行。我所做的一切基本上都是运行bundle install,然后除了这个Ruby gem之外,其他一切都可以正常工作。请给予建议!

current directory: /home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /home/decil/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
client.c: In function ‘nogvl_read_query_result’:
client.c:439:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
  439 |   my_bool res = mysql_read_query_result(client);
      |   ^~~~~~~
      |   bool
client.c: In function ‘rb_query’:
client.c:687:14: warning: passing argument 1 of ‘rb_rescue2’ from incompatible pointer type [-Wincompatible-pointer-types]
  687 |   rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
      |              ^~~~~~~~~~~~~
      |              |
      |              VALUE (*)(void *) {aka long unsigned int (*)(void *)}
In file included from /home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby.h:33,
                 from ./mysql2_ext.h:8,
                 from client.c:1:
/home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby/ruby.h:1988:18: note: expected ‘VALUE (*)(VALUE)’ {aka ‘long unsigned int (*)(long unsigned int)’} but argument is of type ‘VALUE (*)(void *)’ {aka ‘long unsigned int (*)(void *)’}
 1988 | VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
      |                  ^~~~~~~~~~~~~~~
client.c:695:16: warning: passing argument 1 of ‘rb_rescue2’ from incompatible pointer type [-Wincompatible-pointer-types]
  695 |     rb_rescue2(do_query, (VALUE)&async_args, disconnect_and_raise, self, rb_eException, (VALUE)0);
      |                ^~~~~~~~
      |                |
      |                VALUE (*)(void *) {aka long unsigned int (*)(void *)}
In file included from /home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby.h:33,
                 from ./mysql2_ext.h:8,
                 from client.c:1:
/home/decil/.rbenv/versions/2.7.1/include/ruby-2.7.0/ruby/ruby.h:1988:18: note: expected ‘VALUE (*)(VALUE)’ {aka ‘long unsigned int (*)(long unsigned int)’} but argument is of type ‘VALUE (*)(void *)’ {aka ‘long unsigned int (*)(void *)’}
 1988 | VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
      |                  ^~~~~~~~~~~~~~~
client.c: In function ‘_mysql_client_options’:
client.c:762:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
  762 |   my_bool boolval;
      |   ^~~~~~~
      |   bool
client.c:797:10: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean ‘MYSQL_DEFAULT_AUTH’?
  797 |     case MYSQL_SECURE_AUTH:
      |          ^~~~~~~~~~~~~~~~~
      |          MYSQL_DEFAULT_AUTH
client.c:797:10: note: each undeclared identifier is reported only once for each function it appears in
client.c: In function ‘set_secure_auth’:
client.c:1185:38: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean ‘MYSQL_DEFAULT_AUTH’?
 1185 |   return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
      |                                      ^~~~~~~~~~~~~~~~~
      |                                      MYSQL_DEFAULT_AUTH
client.c:1186:1: warning: control reaches end of non-void function [-Wreturn-type]
 1186 | }
      | ^
client.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
make: *** [Makefile:245: client.o] Error 1

你的 mysql2 gem 版本和 Rails 3 都不兼容 Ruby 2.7。如果你需要在项目中使用这些旧的 gem,你也需要一个更旧的 Ruby 版本。可能是 Ruby <= 2.2。根据你具体的 gem 版本,甚至可能需要更老的版本。 - Holger Just
3个回答

2

与Rails 3兼容的mysql2 gem的最新版本是v0.3.21(source)。

mysql2 gem v0.3.21依赖于MySQL本身的my_bool数据类型。

MySQL 5.7具有my_bool数据类型,但在MySQL 8.0中已被删除(source)。

Ubuntu 20.04没有MySQL 5.7,只有8.0+(source)。

因此,您需要从MySQL自己的apt存储库安装MySQL 5.7,并阻止服务器从Ubuntu的apt存储库安装任何MySQL内容
我刚刚完成了所有这些步骤,并成功在Ubuntu 20.04 LTS上运行了Rails 3.2应用程序。
(另外,Rails 3.2.x仅与Ruby <= 2.3.x兼容。)

2
我曾经遇到过0.4.5版本的类似问题,但是在0.4.10版本中这个问题得到了解决。
请在您的Gemfile中添加以下内容进行尝试:
gem 'mysql2', '0.4.10'

mysql2 v0.4.x 不兼容 Rails 3。 - Andy Stewart
用Rails 4.2.0为我解决了这个问题 - 谢谢 - undefined

1

我的环境:ruby2.3,rails3,ubuntu20服务器

首先卸载mysql5.8,并安装mysql5.7

你可以查看这个 链接描述

但最重要的是,在安装gem mysql2'0.3.11'之前,确保libmysqlclient-dev的版本正确。

默认的libmysqlclient-dev版本是8.0

我下载了 libmysqlclient20_5.7.35-1ubuntu18.04_amd64.deb libmysqlclient-dev_5.7.35-1ubuntu18.04_amd64.deb 并使用sudo dpkg -i命令进行安装

就是这样


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接