For MacOS Catalina, visit Install mysql2 on MacOS Catalina
Installing mysql2
gem errors on MacOS Mojave.
Make sure openssl
is installed on Mac via Homebrew.
brew install openssl
Install mysql2
gem.
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
This issue persist in Big Sur:
urrent directory: /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib'
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/mysql2-0.5.3/gem_make.out
bash-3.2$ gem install mysql2 -v '0.5.3' -- --with-mysql-config=/usr/local/opt/mysql-client/bin/mysql_config --srcdir=/usr/local/opt/mysql/include --platform=ruby --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
Building native extensions with: '--with-mysql-config=/usr/local/opt/mysql-client/bin/mysql_config --srcdir=/usr/local/opt/mysql/include --platform=ruby --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/dorhun/.rbenv/versions/2.6.3/bin/ruby -I /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20210624-12722-nl7ij9.rb extconf.rb --with-mysql-config=/usr/local/opt/mysql-client/bin/mysql_config --srcdir=/usr/local/opt/mysql/include --platform=ruby --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
Cannot find mysql_config at /usr/local/opt/mysql-client/bin/mysql_config
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/dorhun/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysql-config
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/mysql2-0.5.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/dorhun/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/extensions/-darwin-20/2.6.0/mysql2-0.5.3/gem_make.out