Slide 1

Slide 1 text

Dive into ‘An error occurred while installing mysql2’ 2019.11.06 Brown Bag Meeting

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

mysql2 ͷΠϝʔδ • ؀ڥߏங࣌ʹඞ͚ͣ͜Δ΍ͭ • 1೥ʹҰճ͋Δ͔ͳ͍͔ͳͷͰຖճ๨ΕΔ • ωοτͰݟ͔ͭΔʮढจʯΛএ͑ͯղܾ͢Δ΍ͭ • ढจ΋౰ͨΓ֎Ε͕͋Δ

Slide 4

Slide 4 text

ࠓ೔࿩͢͜ͱ • mysql2 ͕ͲΜͳ໾ׂΛ͍࣋ͬͯΔͷ͔ • ʮωοτͰर͑Δढจʯ͕ͳΜͳͷ͔ • macOS with Homebrew ͷ؀ڥͰ mysql2 ͷ compile Ͱࣦഊ͠ ͨ࣌ͷਖ਼͍͠ղܾํ๏

Slide 5

Slide 5 text

ࠓ೔࿩͞ͳ͍͜ͱ • Windows/Linux Ͱͷ؀ڥߏங • फڭతͳཧ༝ͳͲʹΑΓ Homebrew ͕࢖͑ͳ͍ঢ়گͰͷ؀ڥ ߏங

Slide 6

Slide 6 text

mysql2

Slide 7

Slide 7 text

mysql2 • Ruby Ͱ͸ʮRuby֦ுϥΠϒϥϦʯͱ͍͏΋ͷΛ࡞Δ͜ͱ͕Ͱ͖Δ • ͜ΕʹΑΓ C ͷίʔυΛ Ruby ͔Βݺͼग़͢͜ͱ͕Մೳ • mysql2 ͸ C Ͱ࣮૷͞Εͨ libmysqlclient Λݺͼग़͢ Ruby ֦ுϥΠϒϥϦ • Αͬͯ mysql2 Λ bundle install ͢Δࡍ͸ɺґଘ͢Δ C ϥΠϒϥϦͷ compile ͢Δඞཁ͕͋Δ

Slide 8

Slide 8 text

Α͘ݟΔढจ 1 $ bundle config --global build.mysql2 \ --with-opt-dir="$(brew --prefix openssl)"

Slide 9

Slide 9 text

--with-opt-dir • mkmf Ruby ͷ֦ுϥΠϒϥϦͷͨΊͷ Make fi le Λ࡞੒͢ΔϥΠϒϥϦͰ͢ɻ ͜ͷϥΠϒϥϦ͸௨ৗɺextconf.rb ͱ͍͏໊લͷ ruby εΫϦϓτ͔Β require ͞Ε·͢ • extconf.rb ࣮ߦ࣌ͷΦϓγϣϯͷҰͭ ϔομϑΝΠϧɺϥΠϒϥϦϑΝΠϧΛ୳ࡧ͢ΔσΟϨΫτϦ DIR/includeɺDIR/lib Λ ͦΕͧΕ௥Ճ͠·͢ɻ library mkmf (Ruby 2.6.0) - https://docs.ruby-lang.org/ja/latest/library/mkmf.html

Slide 10

Slide 10 text

Α͘ݟΔढจ 1 (࠶ܝ) $ bundle config --global build.mysql2 \ --with-opt-dir="$(brew --prefix openssl)"

Slide 11

Slide 11 text

Α͘ݟΔढจ 1 ղઆ • brew $ brew --pre fi x openssl /usr/local/opt/openssl • --with-opt-dir /usr/local/opt/openssl/lib /usr/local/opt/openssl/include Λ୳ࡧύεʹ௥Ճ library mkmf (Ruby 2.6.0) - https://docs.ruby-lang.org/ja/latest/library/mkmf.html

Slide 12

Slide 12 text

Α͘ݟΔढจ 2 $ bundle config —global build.mysql2 \ --with-ldflags=-L/usr/local/opt/openssl/li b

Slide 13

Slide 13 text

--with-ld fl ags • LDFLAGS ֦ுϥΠϒϥϦΛϦϯΫ͢Δͱ͖ͷϦϯΧͷΦϓγϣϯɺ ϥΠ ϒϥϦϑΝΠϧͷσΟϨΫτϦΛࢦఆ͢ΔจࣈྻͰ͢ɻ variable $LDFLAGS (Ruby 2.6.0) - https://docs.ruby-lang.org/ja/latest/method/Kernel/v/LDFLAGS.html

Slide 14

Slide 14 text

Α͘ݟΔढจ 2 ղઆ • --with-ld fl ags /usr/local/opt/openssl/lib Λ୳ࡧύεʹ௥Ճ͍ͯ͠Δ͚ͩ library mkmf (Ruby 2.6.0) - https://docs.ruby-lang.org/ja/latest/library/mkmf.html

Slide 15

Slide 15 text

Α͘ݟΔढจ 3 $ gem install mysql2 -- \ --with-mysql-dir=$(brew --prefix mysql) \ --with-mysql-lib=$(brew --prefix mysql)/lib \ --with-mysql-include=$(brew --prefix mysql)/include \ --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config

Slide 16

Slide 16 text

General Instructions from mysql2 gem By default, the mysql2 gem will try to find a copy of MySQL in this order : • Option --with-mysql-dir, if provided (see below) . • Option --with-mysql-config, if provided (see below) . • Several typical paths for mysql_config (default for the majority of users) . • The directory /usr/local.

Slide 17

Slide 17 text

Con fi guration options from mysql2 gem • --with-mysql-dir[=/path/to/mysqldir] - Specify the directory where MySQL is installed. The mysql2 gem will not use mysql_config, but will instead look at mysqldir/lib and mysqldir/include for the library and header files. This option is mutually exclusive with —with-mysql-config . • --with-mysql-config[=/path/to/mysql_config] - Specify a path to the mysql_config binary provided by your copy of MySQL. The mysql2 gem will ask this mysql_config binary about the compiler and linker arguments needed. This option is mutually exclusive with --with-mysql-dir.

Slide 18

Slide 18 text

͓·͚ $ brew install myslq-clien t If you need to have openssl first in your PATH run : echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profil e 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 " 
 ——- or ——-
 
 If you need to have mysql-client first in your PATH run : echo 'set -g fish_user_paths "/usr/local/opt/mysql-client/bin" $fish_user_paths' >> ~/.config/fish/config.fis h For compilers to find mysql-client you may need to set : set -gx LDFLAGS "-L/usr/local/opt/mysql-client/lib " set -gx CPPFLAGS "-I/usr/local/opt/mysql-client/include "

Slide 19

Slide 19 text

͓·͚2 • 2019-10-14 ʹ MySQL 5.6.46 ͕ϦϦʔε It is now possible to compile MySQL 5.6 using OpenSSL 1.1.1, enabling compilation support for MySQL 5.6 against OpenSSL even when OpenSSL 1.0.2 reaches End of Life status at the end of 2019. MySQL :: MySQL 5.6 Release Notes :: Changes in MySQL 5.6.46 (2019-10-14, General Availability) 
 https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-46.html