How to install MySQL gem on Mac OS X

前端 未结 10 1224
情歌与酒
情歌与酒 2020-12-29 12:30

What do I need to install mysql gem on Mac OS X ? I\'m getting error \"failed to build native extensions\".

相关标签:
10条回答
  • 2020-12-29 13:08

    I installed MySQL with Homebrew and I had to use this to finally be able to upgrade the gem:

    gem install mysql2 -- --with-mysql-dir=/usr/local/opt/mysql/
    
    0 讨论(0)
  • 2020-12-29 13:14

    if you already have MySQL server running elsewhere on the network and would like to still install the gem without having to install MySQL try the following

    brew install mysql-connector-c
    

    followed by

    gem install mysql
    
    0 讨论(0)
  • I'm using Mac OS X Mountain Lion, and installed MySQL with DMG.

    gem install do_mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
    

    and

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
    

    This works for me ;)

    0 讨论(0)
  • 2020-12-29 13:23

    Install MySQL first, either by using binary or Homebrew.

    Then:

    gem install mysql2
    

    Or:

    gem install ruby-mysql
    

    Just pick one and you are good to go.


    Edit

    In case you upgraded to MySQL version 5.6.12 on OS X, mysql2 will fail to compile. Solution is to downgrade MySQL as described here: https://stackoverflow.com/a/17252887/45254


    Edit2

    In case you don't want to have mysql installed (maybe you use docker to manage your services) but do want to use mysql2 gem, you can instead install mysql-connector-c (using homebrew).

    0 讨论(0)
提交回复
热议问题