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

Dive into ‘An error occurred while installing m...

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

    • mysql2 ͸ C Ͱ࣮૷͞Εͨ libmysqlclient Λݺͼग़͢ Ruby ֦ுϥΠϒϥϦ • Αͬͯ mysql2 Λ bundle install ͢Δࡍ͸ɺґଘ͢Δ C ϥΠϒϥϦͷ compile ͢Δඞཁ͕͋Δ
  2. --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
  3. Α͘ݟΔढจ 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
  4. Α͘ݟΔढจ 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
  5. Α͘ݟΔढจ 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
  6. 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.
  7. 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.
  8. ͓·͚ $ 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 "
  9. ͓·͚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