安装mysql2 (0.3.21)时出现错误,Bundler无法继续。

15

当我尝试打包一个应用程序时,为什么会出现这个错误?我已经尝试按照建议安装gem install mysql2 -v '0.3.21',但是它不能正确安装。另外,我正在macOS High Sierra上运行。对于这个问题,因为这是我第一次使用ruby,所以我的措辞可能不太好,请见谅。

 To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/mysql2-0.3.21/mkmf.log

current directory: /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling infile.c
compiling client.c
client.c:439:3: error: use of undeclared identifier 'my_bool'
  my_bool res = mysql_read_query_result(client);
  ^
client.c:441:19: error: use of undeclared identifier 'res'
  return (void *)(res == 0 ? Qtrue : Qfalse);
                  ^
client.c:762:3: error: use of undeclared identifier 'my_bool'
  my_bool boolval;
  ^
client.c:793:7: error: use of undeclared identifier 'boolval'
      boolval = (value == Qfalse ? 0 : 1);
      ^
client.c:794:17: error: use of undeclared identifier 'boolval'
      retval = &boolval;
                ^
client.c:797:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
    case MYSQL_SECURE_AUTH:
         ^~~~~~~~~~~~~~~~~
         MYSQL_DEFAULT_AUTH
/usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
client.c:798:7: error: use of undeclared identifier 'boolval'
      boolval = (value == Qfalse ? 0 : 1);
      ^
client.c:799:17: error: use of undeclared identifier 'boolval'
      retval = &boolval;
                ^
client.c:830:38: error: use of undeclared identifier 'boolval'
        wrapper->reconnect_enabled = boolval;
                                     ^
client.c:1185:38: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
  return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
                                     ^~~~~~~~~~~~~~~~~
                                     MYSQL_DEFAULT_AUTH
/usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
10 errors generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/gems/mysql2-0.3.21 for inspection.
Results logged to /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/mysql2-0.3.21/gem_make.out

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'http://rubygems.org/'` succeeds before bundling.

你能添加他们提到的日志文件的内容吗? - Fishdigger
5个回答

16

通过降级我的mysql版本并使用mysql v5.7编译mysql2来解决问题。

对于Mac用户:

brew install mysql@5.7

gem install mysql2 -v '0.3.21' -- --with-mysql-include=/usr/local/Cellar/mysql@5.7/5.7.25/include/mysql --with-mysql-lib=/usr/local/Cellar/mysql@5.7/5.7.25/lib

参考:https://github.com/brianmario/mysql2#configuration-options


10

所以,经过一番搜索,我自己成功解决了问题。基本上,gemfile中写的mysql2版本与代码中写的版本不一致,因此在尝试安装mysql2时,版本之间的语法差异导致了这个错误。要解决这个问题,你必须打开gemfile,然后更改mysql2的版本号。我把我的版本更改为以下内容:

 gem 'mysql2', '~> 0.4.10'

保存文件,再次尝试安装,应该就可以了


适用于我,Ruby 2.3.8 和 Rails 3.2.11 - Fatima

7

1
对我来说,解决方案是安装mysql-connector-c,brew install mysql-connector-c。在我的情况下,它已经安装了,但我不得不使用强制覆盖重新链接它(控制台中的消息会告诉您在您的情况下要做什么)。

0

我遇到了同样的问题。正如错误中所示,存在代码解释问题。这是由于gemfile中编写的mysql2版本与代码中使用的版本不匹配引起的。 要解决此问题,我运行以下命令:
- gem install mysql2 (它将安装最新的mysql2版本)
- 在我的gemfile中,我将gem 'mysql2','~>0.3.1'更改为gem 'mysql2'


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