mysql2: mysql2 does not build with mysql-client 8.3.0

Compiling mysql2 with mysql-client 8.3.0 fails:

❯ make
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
client.c:1438:3: error: call to undeclared function 'mysql_ssl_set'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  mysql_ssl_set(wrapper->client,
  ^
client.c:1438:3: note: did you mean 'mysql_close'?
/opt/homebrew/opt/mysql-client/include/mysql/mysql.h:797:14: note: 'mysql_close' declared here
void STDCALL mysql_close(MYSQL *sock);
             ^
2 warnings and 1 error generated.
make: *** [client.o] Error 1

mysql_ssl_set was deprecated on 8.2 and removed on 8.3.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 22 (5 by maintainers)

Commits related to this issue

Most upvoted comments

No need to downgrade or uninstall, brew handles various versions of same package in parallel. You can try:

brew install mysql-client@8.0 bundle config --local build.mysql2 -- --with-mysql-dir=$(brew --prefix mysql-client@8.0) bundle install

Depending on you environment you can get other errors, if so, let me know.

@xinlangzi I had the same issue and I solved it by doing the following:

  • brew uninstall mysql to completely uninstall mysql from my Mac
  • brew install mysql-client@8.0 to only install the client needed by the gem
  • gem install mysql2 worked

I then connected my Rails app to a Mysql 8.2 instance via Docker.

Hope this can help someone 😃

If you’re currently having issues on a mac and homebrew, this is what you should do to get your environment back:

1) Uninstall current installed version of mysql-client:

$ brew uninstall mysql-client

2) Download 8.2 formulae:

$ wget https://raw.githubusercontent.com/Homebrew/homebrew-core/2f35529519fb6a2cc361ce3d464a1bd181505a54/Formula/m/mysql-client.rb

Or with curl:

curl https://raw.githubusercontent.com/Homebrew/homebrew-core/2f35529519fb6a2cc361ce3d464a1bd181505a54/Formula/m/mysql-client.rb -o mysql-client.rb

3) Install 8.2:

$ brew install ./mysql-client.rb

For anyone who has the server running on the same system they are trying to install the gem on…

I was able to get around uninstalling or downgrading my MySQL server by installing the mysql-client at version 8.2 using the info from @xjunior above and then simply calling the following:

gem install mysql2 -- --with-mysql-dir="/opt/homebrew/opt/mysql-client"

Hopefully we get an official release to fix this soon though, however with a year between releases I’m not hopeful it’ll be fast.

For homebrew users, there’s also a pinned formula available at 8.0:

$ brew uninstall mysql-client

$ brew install mysql-client@8.0

@xinlangzi Your log says you still have 8.3.0 installed. It is possible you have it installed with the mysql homebrew formula instead of the mysql-client formula described in the other workaround. You can find out by running brew list | grep mysql If so you can try

brew uninstall mysql
brew install mysql@8.0
gem install mysql2

as a workaround until ~either mysql 8.3 or the gem is fixed~ you get the code from #1347

@xjunior

I follow your idea to install mysql-client 8.2. But it did not help me out:

Installing mysql2 0.5.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/mysql2-0.5.5/ext/mysql2
/Users/xinlangzi/.rvm/rubies/ruby-3.1.3/bin/ruby -I /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0 extconf.rb
--with-opt-dir\=/opt/homebrew/opt/openssl@3
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
-----
Using --with-openssl-dir=/opt/homebrew/opt/openssl@3
-----
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.3.0/lib
-----
creating Makefile

current directory: /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240131-58086-wij5w2 sitelibdir\=./.gem.20240131-58086-wij5w2 clean

current directory: /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240131-58086-wij5w2 sitelibdir\=./.gem.20240131-58086-wij5w2
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x
[-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x
[-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
client.c:1438:3: error: call to undeclared function 'mysql_ssl_set'; ISO C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
  mysql_ssl_set(wrapper->client,
  ^
client.c:1438:3: note: did you mean 'mysql_close'?
/opt/homebrew/Cellar/mysql/8.3.0/include/mysql/mysql.h:797:14: note: 'mysql_close' declared here
void STDCALL mysql_close(MYSQL *sock);
             ^
2 warnings and 1 error generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/xinlangzi/.rvm/gems/ruby-3.1.3/extensions/arm64-darwin-23/3.1.0/mysql2-0.5.5/gem_make.out

  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:102:in `run'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:43:in `each'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:43:in `make'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:171:in `build_extension'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:205:in `block in build_extensions'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in `each'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/ext/builder.rb:202:in `build_extensions'
  /Users/xinlangzi/.rvm/rubies/ruby-3.1.3/lib/ruby/3.1.0/rubygems/installer.rb:843:in `build_extensions'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/source/rubygems.rb:203:in `install'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/installer/parallel_installer.rb:156:in `do_install'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/installer/parallel_installer.rb:147:in `block in worker_pool'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/worker.rb:62:in `apply_func'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/worker.rb:54:in `loop'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/worker.rb:54:in `process_queue'
  /Users/xinlangzi/.rvm/gems/ruby-3.1.3/gems/bundler-2.4.20/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue.

Did I miss other steps?

No need to downgrade or uninstall, brew handles various versions of same package in parallel. You can try:

brew install mysql-client@8.0 bundle config --local build.mysql2 -- --with-mysql-dir=$(brew --prefix mysql-client@8.0) bundle install

Depending on you environment you can get other errors, if so, let me know.

@lipedjow Thanks, it works for me!

@yboulkaid 8.0 still didn’t do it for me, I don’t quite remember why, but if it works for anyone, it should be better than downloading that formulae 😃

@Uaitt thank you this worked for me 🙏

@lipedjow @Uaitt @lipedjow

Screenshot 2024-03-18 at 7 00 21 PM recently i have done a brew update and then running bundle fails for me, saying "Gem::Ext::BuildError: ERROR: Failed to build gem native extension."

my mysql2 is “05.4” in my Gem file.

Issue was fixed already, update mysql2 gem to new version (0.5.6+) or check my comment above for alternative solution.

but it is not the right solution because brew update will wipe the config out.

You can use brew pin mysql-client to prevent Homebrew from upgrade mysql-client.

However, I think installing mysql-client@8.0 alongside and point your software/library to use that (as @lipedjow suggested) is the correct workaround, as the versioned keg won’t get upgraded to the broken version.

@jairovm there is a an official gem to adapt it to older versions of rails as well. This is also something we’re willing to try.

https://github.com/trilogy-libraries/activerecord-trilogy-adapter

Ultimately, the fix shouldn’t be to downgrade, the maintainers of this gem should fix their code.