Mysql2 Gem versions 0.3.18 uptill 0.4.x won't install in my Ruby on Rails project Ubuntu

Viewed 322

I am working on a Ruby on Rails legacy project. I am trying to set up the whole project environment in my system (Ubuntu 20.4) but I am facing the following issue:

When I run bundle install I get the following error:

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

Again when I run gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/' I get the following error :

Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /home/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21/ext/mysql2
/usr/share/rvm/rubies/ruby-2.2.2/bin/ruby -I /usr/share/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0 -r ./siteconf20201005-54852-6qy3z2.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/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /home/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling infile.c
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 | }
      | ^
make: *** [Makefile:238: client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21 for inspection.
Results logged to /home/syed/.rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/mysql2-0.3.21/gem_make.out
  • Ubuntu - 20.4

  • Ruby - 2.2.2

  • Rails - 4.2.2

  • rvm - 1.29.10

  • MySQL (server, client, etc) - 8.0.21-0ubuntu0.20.04.4

Things I have tried:

  1. bundle install

  2. bundle update

  3. downgrading MySQL version to 5.x.x

  4. tried installing other versions of mysql2 gems like 4.x.x

In my Gemfile: gem 'mysql2', '~> 0.3.21'

In my Gemlock file: mysql2 (0.3.21)

I am getting the following error while doing bundle install no matter what I do :

Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /home/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21/ext/mysql2
/usr/share/rvm/rubies/ruby-2.2.2/bin/ruby -I /usr/share/rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0 -r ./siteconf20201005-54852-6qy3z2.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/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /home/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling infile.c
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 | }
      | ^
make: *** [Makefile:238: client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /home/syed/.rvm/gems/ruby-2.2.2/gems/mysql2-0.3.21 for inspection.
Results logged to /home/syed/.rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/mysql2-0.3.21/gem_make.out

Note: I have constraints that I cannot change rails or ruby version as this is a legacy project.

0 Answers
Related