在Ubuntu 20.04安装mysql2 gem版本“0.3.21”时出现错误。

3

我一直在尝试在我的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

到目前为止,我已经按照Stackoverflow上其他类似问题的解决方案进行操作,例如安装 default-libmysqlclient-devlibmysqlclient-dev ,但是到目前为止还没有运气。

我的MySQL服务器版本是5.7.35

4个回答

3

也许可以试试这个:

sudo apt remove libmysqlclient-dev

并且

sudo apt install libmariadb-dev

1

谢谢。上面的答案对我有帮助。只是一开始我需要找出我的mysql在哪里。

which mysql
/usr/bin/mysql
gem install mysql2 -v '0.3.21' -- --srcdir=/usr/bin/mysql

1
问题的原因是您安装了一个不兼容的libmysqlclient-dev软件包版本,这在Ubuntu 20.04中默认对应于MySQL 8.0。
您只需要删除已安装的版本,并按照以下步骤安装适当的版本。
考虑到我尝试的版本是MySQL 5.7.39,但您可以在其他存储库中找到5.7.35版本;这里有一个链接:http://repo.mysql.com/apt/ubuntu/pool/mysql-5.7/m/mysql-community 删除当前已安装的版本:
sudo apt-get remove libmysqlclient-dev

使用dpkg -i命令下载并安装带有依赖包的软件包。
wget http://mirrors.kernel.org/ubuntu/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.39-0ubuntu0.18.04.2_amd64.deb
          
wget http://mirrors.kernel.org/ubuntu/pool/main/m/mysql-5.7/libmysqlclient20_5.7.39-0ubuntu0.18.04.2_amd64.deb
          
sudo dpkg -i libmysqlclient20_5.7.39-0ubuntu0.18.04.2_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.7.39-0ubuntu0.18.04.2_amd64.deb

更新: 我需要在另一台旧的机器上解决这个问题,它运行着Ubuntu 20.04和MySQL 5.7服务器。之前提供的软件包链接已经失效,所以我使用了以下链接:

wget https://downloads.mysql.com/archives/get/p/23/file/libmysqlclient20_5.7.36-1ubuntu18.04_amd64.deb
wget https://downloads.mysql.com/archives/get/p/23/file/libmysqlclient-dev_5.7.36-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient20_5.7.36-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.7.36-1ubuntu18.04_amd64.deb

然后在Ubuntu 20.04上安装mysql2 gem版本'0.3.21'成功了!

1

我解决了这个问题。我运行了以下命令

gem install mysql2 -v '0.3.21' -- --srcdir=/var/lib/mysql

其中srcdir指向本地安装的mysql。


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