This is my first Qiita post! At first, I was planning to write an article while making a task management app for Rails and Vue, but at the time of rails new, myql installation did not go well and I stumbled, so I decided to write this article. However, the solution is written at the end, and until then it is a story until the solution is reached, so it is better to skip it. If you would like to read my own memorandum, please read it from above. Some people may know the environment, but it's a Mac. (If you use brew with zsh, it's a Mac, right?) As I recently learned, zsh seems to read Z shell.
Anyway, it's rails new.
% rails -v
Rails 6.0.3.4
% rails new memo-memo -d mysql --skip-test
An error occurred immediately w
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.
I will do as I was told.
% gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
Since a Pemission error has occurred, stop thinking and add sudo here as well.
% sudo gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
I'm not sure this time.
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/8.0.22_1/lib
Let's make sure that mysql is installed correctly on the Mac in the first place. Then Brew seemed to be dissatisfied with me and gave me various hints.
% brew info mysql
mysql: stable 8.0.22 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
Conflicts with:
mariadb (because mysql, mariadb, and percona install the same binaries)
percona-server (because mysql, mariadb, and percona install the same binaries)
/usr/local/Cellar/mysql/8.0.22_1 (294 files, 296.5MB) *
Poured from bottle on 2020-12-13 at 08:50:29
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mysql.rb
License: GPL-2.0
==> Dependencies
Build: cmake ✘
Required: [email protected] ✔, protobuf ✔
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Analytics
install: 85,291 (30 days), 236,256 (90 days), 823,613 (365 days)
install-on-request: 83,799 (30 days), 231,594 (90 days), 798,215 (365 days)
build-error: 0 (30 days)
Apparently mariadb and percona-server are conflicting and I wondered if cmake wasn't installed. So, first, I tried installing the simpler cmake. Then I hit brew info mysql again.
% brew install cmake
% brew info mysql
For the time being, I made progress because I changed from ✖️ of cmake to a check mark. For the time being, I checked if mysql can be installed.
% sudo gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
I was able to confirm that the installation was not possible as usual. Now let's check the error firmly.
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201218-6446-1qkv5ft.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/local/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_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 /usr/local/Cellar/mysql/8.0.22_1/lib
-----
creating Makefile
current directory: /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean
current directory: /Library/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/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib'
ld: library not found for -lssl
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 /Library/Ruby/Gems/2.6.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/mysql2-0.5.3/gem_make.out
Should I go through libpath? I will think about it. (I will notice later that this interpretation is wrong)
% export LIBRARY_PATH=/usr/local/Cellar/mysql/8.0.22_1/lib
% sudo gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
However, the content of the error did not change. Since I wrote Gonyo Gonyo after Creating Makefile here, I was running some Makefile when gem install, and in the middle I failed with ld: liblary not found for -lssl and the installation did not fail. I thought. (I apologize if I'm wrong.)
I decided to raise the white flag here and look for someone who had the same problem. Then, the following excellent articles were hit! Troubleshooting when installing mysql2 gem
It was a story that could be solved from the beginning if you look here ww I'm sorry for those who have read this far. Please note that it is a realistic error resolution story while writing Qiita.
In other words, I set the path to LIBRARY_PATH =/usr/local/Cellar/mysql/8.0.22_1/lib, but it says library not found because the library I was looking for was not found, and --with-cppflags By specifying --with-ldflags, you will be able to find the library properly and install it. Please refer to the original article to be exact.
% brew info openssl
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
% sudo gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
% bundle install
Thank you for your hard work. If you did rails new, but if anyone stumbled upon installing mysql, I would appreciate it if you could refer to it.
Recommended Posts