在 Ubuntu 20.04 上安装 mysql2 gem 版本“0.3.21”时出错
Posted
技术标签:
【中文标题】在 Ubuntu 20.04 上安装 mysql2 gem 版本“0.3.21”时出错【英文标题】:Error installing mysql2 gem version '0.3.21' on Ubuntu 20.04 【发布时间】:2021-10-23 01:04:57 【问题描述】:我一直在尝试在我的 Ubuntu 20.04 上安装 mysql2 gem 版本 0.3.21
,但收到以下错误。
构建原生扩展。这可能需要一段时间... 错误:安装 mysql2 时出错: 错误:无法构建 gem 原生扩展。
current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/mysql2-0.3.21/ext/mysql2
/home/user/.rvm/rubies/ruby-2.5.3/bin/ruby -I /home/user/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0 -r ./siteconf20210822-101581-13t36qj.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting libpath to /usr/lib/x86_64-linux-gnu
-----
creating Makefile
current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean
current directory: /home/user/.rvm/gems/ruby-2.5.3/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 ‘_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-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
make: *** [Makefile:242: client.o] Error 1
make failed, exit code 2
到目前为止,我在 *** 上的其他类似问题中遵循了其他解决方案,例如安装 default-libmysqlclient-dev
libmysqlclient-dev
,但到目前为止还没有运气。
我的 MySQL 服务器版本是5.7.35
【问题讨论】:
【参考方案1】:我解决了这个问题。我运行了以下命令
gem install mysql2 -v '0.3.21' -- --srcdir=/var/lib/mysql
其中srcdir指向本地安装的mysql。
【讨论】:
以上是关于在 Ubuntu 20.04 上安装 mysql2 gem 版本“0.3.21”时出错的主要内容,如果未能解决你的问题,请参考以下文章
Ubuntu20.04安装MySQL及配置MySQL workbench
Ubuntu20.04安装MySQL及配置MySQL workbench
如何在 Ubuntu 16.04 上安装 mysql2 [错误:安装 mysql2 时出错:错误:无法构建 gem 本机扩展。] [重复]