Rails error installing mysql2 (mysql2-0.3.20)

后端 未结 5 1349
无人共我
无人共我 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条回答
  • 2021-02-04 04:58

    This worked for me - macOS Catalina

    brew uninstall mysql
    gem uninstall mysql2
    
    brew install mysql@5.7
    brew link mysql@5.7 --force
    gem install mysql2 -v '0.3.21'
    
    # Gemfile
    gem 'mysql2', '0.3.21'
    
    bundle update mysql2
    
    0 讨论(0)
  • 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 >
    
    0 讨论(0)
  • 2021-02-04 05:05

    As of today Homebrew defaults to MySQL 8.0, OpenSSL 1.1 and mysql2 0.5 that work great all together out of the box. However to upgrade of my legacy applications from Rails 3.2 to more recent versions I had to setup local environment on my MacOS BigSur 11.1.

    My goal was to install mysql2 gem version 0.3.x (this is only one allowing smooth migration from Rails 3.2 to Rails 4.2 through versions 4.0 and 4.1) together with mySQL 5.x. Both of them in turn depend on OpenSSL 1.0

    Here is what worked for me:

    // Clean-up all your faulty attempts you did before
    // Homebrew does not store openssl 1.0 anymore, so I had to find alternative — openssl1.0.2t 
    wget https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
    brew install openssl.rb
    
    brew install mysql@5.7
    brew link mysql@5.7 --force
    brew install mysql-client@5.7
    // NB! Pay close attention to path where you have mysql_config and openssl 1.0 installed
    gem install mysql2 -v 0.3.21 -- --with-mysql-config=/usr/local/bin/mysql_config --with-ldflags=-L/usr/local/Cellar/openssl/1.0.2t/lib --with-cppflags=-I/usr/local/Cellar/openssl/1.0.2t/include
    
    

    Voilá:

    Building native extensions with: '--with-mysql-config=/usr/local/bin/mysql_config --with-ldflags=-L/usr/local/Cellar/openssl/1.0.2t/lib --with-cppflags=-I/usr/local/Cellar/openssl/1.0.2t/include'
    This could take a while...
    Successfully installed mysql2-0.3.21
    Parsing documentation for mysql2-0.3.21
    Installing ri documentation for mysql2-0.3.21
    Done installing documentation for mysql2 after 0 seconds
    1 gem installed
    
    0 讨论(0)
  • 2021-02-04 05:06

    I faced the same issue when installing mysql2-0.3.21 on Mac pro.

    Below mentioned solution worked for me (run the below mentioned 3 commands in the terminal pointing to your project folder):

    brew install mysql
    
    gem install mysql2 -v '0.3.21' -- --srcdir=/usr/local/mysql/include
    
    bundle install
    
    0 讨论(0)
  • 2021-02-04 05:11

    I just ran into this problem today. mysql got updated recently, so what worked for me was:

    brew install mysql@5.6
    brew link mysql@5.6 --force
    bundle install
    

    Alternatively, I did not try this solution, but it seems to have worked for other people.

    Installing Mysql 2 gem fails

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