Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dive into ‘An error occurred while installing mysql2’

Dive into ‘An error occurred while installing mysql2’

mysql2 の install になぜ失敗するのか。ググって出てきたコマンドを手当たり次第コピペするは今日でやめにしよう。

Tetsuya Kaneko

November 06, 2019
Tweet

More Decks by Tetsuya Kaneko

Other Decks in Programming

Transcript

  1. Dive into ‘An error occurred while installing mysql2’ 2019.11.06 Brown

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

  4. ࠓ೔࿩͢͜ͱ • mysql2 ͕ͲΜͳ໾ׂΛ͍࣋ͬͯΔͷ͔ • ʮωοτͰर͑Δढจʯ͕ͳΜͳͷ͔ • macOS with Homebrew

    ͷ؀ڥͰ mysql2 ͷ compile Ͱࣦഊ͠ ͨ࣌ͷਖ਼͍͠ղܾํ๏
  5. ࠓ೔࿩͞ͳ͍͜ͱ • Windows/Linux Ͱͷ؀ڥߏங • फڭతͳཧ༝ͳͲʹΑΓ Homebrew ͕࢖͑ͳ͍ঢ়گͰͷ؀ڥ ߏங

  6. mysql2

  7. mysql2 • Ruby Ͱ͸ʮRuby֦ுϥΠϒϥϦʯͱ͍͏΋ͷΛ࡞Δ͜ͱ͕Ͱ͖Δ • ͜ΕʹΑΓ C ͷίʔυΛ Ruby ͔Βݺͼग़͢͜ͱ͕Մೳ

    • mysql2 ͸ C Ͱ࣮૷͞Εͨ libmysqlclient Λݺͼग़͢ Ruby ֦ுϥΠϒϥϦ • Αͬͯ mysql2 Λ bundle install ͢Δࡍ͸ɺґଘ͢Δ C ϥΠϒϥϦͷ compile ͢Δඞཁ͕͋Δ
  8. Α͘ݟΔढจ 1 $ bundle config --global build.mysql2 \ --with-opt-dir="$(brew --prefix

    openssl)"
  9. --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
  10. Α͘ݟΔढจ 1 (࠶ܝ) $ bundle config --global build.mysql2 \ --with-opt-dir="$(brew

    --prefix openssl)"
  11. Α͘ݟΔढจ 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
  12. Α͘ݟΔढจ 2 $ bundle config —global build.mysql2 \ --with-ldflags=-L/usr/local/opt/openssl/li b

  13. --with-ld fl ags • LDFLAGS ֦ுϥΠϒϥϦΛϦϯΫ͢Δͱ͖ͷϦϯΧͷΦϓγϣϯɺ ϥΠ ϒϥϦϑΝΠϧͷσΟϨΫτϦΛࢦఆ͢ΔจࣈྻͰ͢ɻ variable $LDFLAGS

    (Ruby 2.6.0) - https://docs.ruby-lang.org/ja/latest/method/Kernel/v/LDFLAGS.html
  14. Α͘ݟΔढจ 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
  15. Α͘ݟΔढจ 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
  16. 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.
  17. 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.
  18. ͓·͚ $ 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 "
  19. ͓·͚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