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

M1, mysql 5.7, passed bundle install, fails on db:create, #1252

Open
moenegm opened this issue Apr 14, 2022 · 5 comments
Open

M1, mysql 5.7, passed bundle install, fails on db:create, #1252

moenegm opened this issue Apr 14, 2022 · 5 comments

Comments

@moenegm
Copy link

moenegm commented Apr 14, 2022

I have tried the following:

  bundle config build.mysql2 \
  --with-mysql-lib=/usr/local/Cellar/mysql@5.7/5.7.37/lib \
  --with-mysql-dir=/usr/local/Cellar/mysql@5.7/5.7.37 \
  --with-mysql-config=/usr/local/Cellar/mysql@5.7/5.7.37/bin/mysql_config \
  --with-mysql-include=/usr/local/Cellar/mysql@5.7/5.7.37/include/mysql\

gem install mysql2 -v '0.4.10' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install

all passed. But when i run:
bundle exec rake db:create db:structure:load
or
rails db:create

i get this:

rails aborted!
LoadError: dlopen(/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle, 0x0009): symbol not found in flat namespace '_mysql_affected_rows' - /Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.4.10/lib/mysql2.rb:31:in `require'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.4.10/lib/mysql2.rb:31:in `<top (required)>'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler/runtime.rb:60:in `require'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler/runtime.rb:55:in `each'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler/runtime.rb:55:in `block in require'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler/runtime.rb:44:in `each'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler/runtime.rb:44:in `require'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bundler-2.3.7/lib/bundler.rb:176:in `require'
/Users/mohamednegm/Coding/Agate/Mad_Hatcher/madhatchers_staging_patrick/config/application.rb:26:in `<top (required)>'
/Users/mohamednegm/Coding/Agate/Mad_Hatcher/madhatchers_staging_patrick/Rakefile:4:in `require'
/Users/mohamednegm/Coding/Agate/Mad_Hatcher/madhatchers_staging_patrick/Rakefile:4:in `<top (required)>'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:703:in `raw_load_rakefile'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:103:in `load_rakefile'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-5.2.4.4/lib/rails/commands/rake/rake_command.rb:22:in `block in perform'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-5.2.4.4/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-5.2.4.4/lib/rails/command.rb:48:in `invoke'
/Users/mohamednegm/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-5.2.4.4/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'

Note i have this working in a different repository where i'm using ruby 2.7.5 and bundler 2.3.9 but i was told i'm not able to upgrade my ruby version. so is this a ruby version issue or am i missing something?

edit: added preformatting block quotes

@sodabrew
Copy link
Collaborator

sodabrew commented Apr 18, 2022

I see that you are using mysql2 gem 0.4.10. This is very old. Please update it. You are using Rails 5 and MySQL 5.7, this will work well with mysql2 0.5.x.

@will-bissschoff-fa
Copy link

will-bissschoff-fa commented Apr 27, 2022

This worked for me: (using homebrew mysql, arm mac, ruby 3.1.2)

First clear out gems: rm -rf ~/.gem
Then brew reinstall mysql@5.7
Then set:

bundle config build.mysql2 "--with-mysql-lib=/opt/homebrew/opt/mysql@5.7/lib --with-mysql-dir=/opt/homebrew/opt/mysql@5.7 --with-mysql-config=/opt/homebrew/opt/mysql@5.7/bin/mysql_config --with-mysql-include=/opt/homebrew/opt/mysql@5.7/include --with-ldflags=-L/opt/homebrew/opt/openssl@1.1/lib --with-cppflags=-I/opt/homebrew/opt/openssl@1.1/include"

Then bundle install

See: #1229 (comment)

@abhiramvad
Copy link

abhiramvad commented Sep 27, 2022

Facing the same issue and bundle config is not working for me.

Throws the below error:
LoadError: dlopen(/Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): symbol not found in flat namespace (_mysql_affected_rows)

Configuration:

ruby version: 2.6.6 MacOS: Monterey 12.3 Processor: M1 Pro mysql version: 8

@forddavis
Copy link

I have the same issue using ruby version: 2.7.0

Switching to 2.7.2 seems to fix, but it would be nice to know what's going on/how to fix it as I can't update ruby on the server at the moment.

@sodabrew
Copy link
Collaborator

sodabrew commented Aug 25, 2023

Typically this error indicates you need ro recompile with the same Ruby and MySQL versions as you will use. It is not "fixed" by upgrading Ruby, but rather because that prompted you to recompile your compiled gems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants