6

Does anyone know what causes this and how I can fix it? I am trying to install a ruby gem for my project which is an old project running on rails 3, but I'm running on ubuntu 20.04. All I am doing is essentially running bundle install and then I get everything else working except this ruby gem. Please advise!

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
Ryan Glenn
  • 1,325
  • 4
  • 17
  • 30
  • Neither your version of the `mysql2` gem nor Rails 3 are compatible with Ruby 2.7. If you need to use such old gems for your project, you also need an older Ruby version. Likely, that is Ruby <= 2.2. Depending on your specific gem versions, maybe even something still older. – Holger Just Aug 19 '20 at 16:33

3 Answers3

2

The latest version of the mysql2 gem compatible with Rails 3 is v0.3.21 (source).

mysql2 gem v0.3.21 depends on the my_bool datatype in MySQL itself.

MySQL 5.7 has the my_bool datatype but it was removed in MySQL 8.0 (source).

Ubuntu 20.04 does not have MySQL 5.7, only 8.0+ (source).

Therefore you need to install MySQL 5.7 from MySQL's own apt repositories and stop your server from installing any MySQL stuff from Ubuntu's apt repositories.

I just did all this and successfully got a Rails 3.2 app running on Ubuntu 20.04 LTS.

(Also, Rails 3.2.x is only compatible with Ruby <= 2.3.x.)

Andy Stewart
  • 5,013
  • 2
  • 28
  • 38
1

I had a similar issue with version 0.4.5, It worked fine for me with version 0.4.10

Try with the below on your Gemfile:

gem 'mysql2', '0.4.10'
user11350468
  • 1,357
  • 1
  • 6
  • 22
  • mysql2 v0.4.x is not compatible with Rails 3. ([Source](https://github.com/brianmario/mysql2#ruby-on-rails--active-record)) – Andy Stewart Dec 18 '20 at 16:19
1

my env:ruby2.3,rails3,ubuntu20 server

first of all uninstall mysql5.8, and install mysql5.7

you can see this enter link description here

but the most important is that make sure the libmysqlclient-dev's version before you install gem mysql2'0.3.11' .

the default libmysqlclient-dev's version is 8.0

i download the libmysqlclient20_5.7.35-1ubuntu18.04_amd64.deb libmysqlclient-dev_5.7.35-1ubuntu18.04_amd64.deb and install them sudo dpkg -i them

that ok

chinacheng
  • 161
  • 1
  • 5