Rails error installing mysql2 (mysql2-0.3.20)

后端 未结 5 1356
无人共我
无人共我 2021-02-04 04:15

I am trying to get a rails project up and running on my local machine. When I do bundle install

Fetching mysql2 0.3.20
Installing mysql2 0.3.20 with native ext         


        
5条回答
  •  猫巷女王i
    2021-02-04 04:59

    My MacBook Pro had a disk crash during upgrade to MacOS Mojave (not pretty!), so I had to reestablish all my code projects afterwards.

    One particular project proved extremely hard to get up and running and I've spent several hours today looking for a way to get mysql2-0.3.21 running for an older RoR project; Ruby version 2.1.1p76 with Rails 4.1.1.

    Finally, I succeeded by following this advice: https://github.com/brianmario/mysql2/issues/1010#issuecomment-460257986

    I did the following steps:

    1. Start by removing all installed versions of mysql2 from your gemset:

      gem uninstall mysql2
      
    2. Then install MySQL 5.6, I already have MySQL 8.0.17 installed, so 5.6 is installed as a keg only which is fine:

      brew install mysql@5.6
      
    3. Then install mysql2 version 0.3.21 with the following command:

      gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/Cellar/mysql@5.6/5.6.42/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
      

    The OpenSSL part can probably be left out and you can change the mysql2 version number depending on what version of Rails your project is running.

    After the above steps I was able to start the Rails console again and query the database:

    Loading development environment (Rails 4.1.1)
    2.1.1 :001 > User.count
       (18.7ms)  SELECT COUNT(*) FROM `users`  WHERE `users`.`deleted_at` IS NULL
     => 1222
    2.1.1 :002 >
    

提交回复
热议问题