Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql2 does not build with mysql-client 8.3.0 #1346

Closed
xjunior opened this issue Jan 30, 2024 · 22 comments · Fixed by #1352
Closed

mysql2 does not build with mysql-client 8.3.0 #1346

xjunior opened this issue Jan 30, 2024 · 22 comments · Fixed by #1352

Comments

@xjunior
Copy link
Contributor

xjunior commented Jan 30, 2024

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.

@xjunior
Copy link
Contributor Author

xjunior commented Jan 30, 2024

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

@yboulkaid
Copy link

yboulkaid commented Jan 30, 2024

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

$ brew uninstall mysql-client

$ brew install mysql-client@8.0

@xjunior
Copy link
Contributor Author

xjunior commented Jan 30, 2024

@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 :)

@noahgregory-basis
Copy link

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

@xinlangzi
Copy link

@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?

@Uaitt
Copy link

Uaitt commented Jan 31, 2024

@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 😃

@dcorking
Copy link

dcorking commented Jan 31, 2024

@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

@mrpunkin
Copy link

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.

@bmsheets
Copy link

@Uaitt thank you this worked for me 🙏

@Ahmedgagan
Copy link

@Uaitt thanks a lot, it worked for me too 🙌

@satyakampandya
Copy link

I've successfully installed the mysql2 gem, but I'm encountering the following error while attempting to start rails server using rails s:

"cannot load such file -- /Users/satyakam/.rvm/gems/ruby-2.5.6/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle (LoadError)"

Could you please assist me with resolving this issue?

@Ahmedgagan
Copy link

Hey @satyakampandya
I also faced a similar issue but it was fixed by installing mysql using brew.

brew install mysql

@satyakampandya
Copy link

Hey @Ahmedgagan
I'm using a MacBook Pro M3 with Sonoma 14.3. I had it working fine just before updating to MySQL 8.3. However, now I'm facing issues, and it's not even working with MySQL 8.2.

The command you provided installs MySQL 8.3, and I can successfully install the mysql2 gem. However, I'm running into the following error when trying to start the Rails server.

cannot load such file -- /Users/satyakam/.rvm/gems/ruby-2.5.6/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle (LoadError)

@xjunior
Copy link
Contributor Author

xjunior commented Feb 2, 2024

@satyakampandya try a pristine installation of mysql2

@lipedjow
Copy link

lipedjow commented Feb 4, 2024

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.

@jairovm
Copy link

jairovm commented Feb 5, 2024

I ended up using the trilogy adapter 😅 https://dev.to/justthev/benchmarking-trilogy-is-it-really-the-future-of-rails--3neg It requires Rails 7.1, tho.

@xjunior
Copy link
Contributor Author

xjunior commented Feb 5, 2024

@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

@fabiendv
Copy link

fabiendv commented Feb 6, 2024

Same issue. When we can expect a patch to be implemented?
Downgrading works as a workaround, but it is not the right solution because brew update will wipe the config out.

@sikachu
Copy link

sikachu commented Feb 6, 2024

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.

@xjunior
Copy link
Contributor Author

xjunior commented Feb 6, 2024

I'm sticking with 8.0 and pining it on developers machines too. Yet, I'd like to understand why there hasn't been any feedback on #1347 yet. I don't believe my PR has the correct solution, as it could drop support for older versions of mysql-client that don't implement mysql_options, but I expected to hear from the maintainers faster since this is breaking so many environments out there.

All of that said, Trilogy looks like a great solution and even an improvement, since it won't depend on any external library like mysql-client and thus fewer configs, and fewer steps to set up a project.

@satyakampandya
Copy link

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!

@lipedjow
Copy link

@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.

lukaszreszke added a commit to RailsEventStore/rails_event_store that referenced this issue Mar 19, 2024
https: //github.com/brianmario/mysql2/issues/1346
Co-authored-by: Szymon Fiedler <szymon.fiedler@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet