Error installing mysql2: Failed to build gem native extension

后端 未结 27 2803
清酒与你
清酒与你 2020-11-22 08:06

I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysq

相关标签:
27条回答
  • 2020-11-22 09:10

    For windows user: You set the lib and include path of your mysql, for instance, if youre using xampp you can have like this:

    gem install mysql2 -- '--with-mysql-lib="C:\xampp\mysql\lib" --withmysql-include="C:\xampp\mysql\include"'
    
    0 讨论(0)
  • 2020-11-22 09:11

    here is a solution for the windows users, hope it helps!

    Using MySQL with Rails 3 on Windows

    • Install railsinstaller -> www.railsinstaller.org (I installed it to c:\Rails)

    • Install MySQL (I used MySQL 5.5) -> dev.mysql.com/downloads/installer/

    --- for mySQL installation ---

    If you dont already have these two files installed you might need them to get your MySQL going

    vcredist_x86.exe -> http://www.microsoft.com/download/en/details.aspx?id=5555 dotNetFx40_Full_x86_x64.exe -> http://www.microsoft.com/download/en/details.aspx?id=17718

    Use default install Developer Machine

    -MySQL Server Config-
    port: 3306
    windows service name: MySQL55
    mysql root pass: root (you can change this later)
    (username: root)
    -MySQL Server Config-

    --- for mySQL installation ---


    --- Install the mysql2 Gem ---

    Important: Do this with Git Bash Command Line(this was installed with railsinstaller) -> start/Git Bash

    gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'

    Now the gem should have installed correctly

    Lastly copy the libmysql.dll file from
    C:\Program Files\MySQL\MySQL Server 5.5\lib
    to
    C:\Rails\Ruby1.9.2\bin

    --- Install the mysql2 Gem ---


    You will now be able to use your Rails app with MySQL, if you are not sure how to create a Rails 3 app with MySQL read on...


    --- Get a Rails 3 app going with MySQL ---

    Open command prompt(not Git Bash) -> start/cmd
    Navigate to your folder (c:\Sites)
    Create new rails app

    rails new world
    

    Delete the file c:\Sites\world\public\index.html
    Edit the file c:\Sites\world\config\routes.rb
    add this line -> root :to => 'cities#index'

    Open command prompt (generate views and controllers)

    rails generate scaffold city ID:integer Name:string CountryCode:string District:string Population:integer
    



    Edit the file c:\Sites\world\app\models\city.rb to look like this

    class City < ActiveRecord::Base
     set_table_name "city"
    end
    

    Edit the file c:\Sites\world\config\database.yml to look like this

    development:
    adapter: mysql2
    encoding: utf8
    database: world
    pool: 5
    username: root
    password: root
    socket: /tmp/mysql.sock
    

    add to gemfile

    gem 'mysql2'
    

    Open command prompt windows cmd, not Git Bash(run your app!)
    Navigate to your app folder (c:\Sites\world)

    rails s
    

    Open your browser here -> http://localhost:3000

    --- Get a Rails 3 app going with MySQL ---

    0 讨论(0)
  • 2020-11-22 09:11

    After you get the mysql-dev issues corrected, you may need to remove the bad mysql2 install. Look carefully at the messages after $ bundle install. You may need to

    rm -rf vendor/cache/
    rm -rf ./Zentest
    

    This will clear out the bad mysql2 installation so that a final $ bundle install can create a good one.

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