How do I install the Rails MySQL adapter?

前端 未结 5 513
Happy的楠姐
Happy的楠姐 2021-01-02 08:52

There\'s not much more to my question than that. gem install mysql doesn\'t work and I haven\'t found anything by Googling.

When I try gem install

相关标签:
5条回答
  • 2021-01-02 09:12

    I assume you are working with Rails.

    In your Gemfile:

    gem 'mysql2'
    

    Then in your terminal:

    bundle
    
    0 讨论(0)
  • 2021-01-02 09:18

    I'll just leave this here:

    I ran into a similar problem, then realized I couldn't install the mysql2 gem without having MySQL installed on my development machine (even though I'm only using the mysql2 gem to connect to a remote MySQL server).

    ::forehead slap::

    brew install mysql
    

    then, in my Gemfile:

    gem 'mysql2', '~> 0.3.11'
    

    followed by a quick

    bundle install
    

    Success!

    0 讨论(0)
  • 2021-01-02 09:18

    In 2013, Using Ubuntu 12.04, this worked for me:

    sudo apt-get install mysql-client libmysqlclient-dev
    
    bundle install
    
    0 讨论(0)
  • 2021-01-02 09:26

    It looks like you still need to install MySQL's development libraries. These are required for the gem to build successfully on your system.

    [Edit] Seems the RoR Wiki is no longer available. But, Ubuntu has offered their own walkthrough which suggests:

    sudo apt-get install mysql-server mysql-client
    sudo apt-get install libmysql-ruby libmysqlclient-dev
    sudo gem install mysql
    

    See http://wiki.rubyonrails.org/database-support/mysql#installation for more detail.

    Example: Ubuntu

    sudo apt-get install mysql-server mysql-server-5.0 libmysqlclient15off \
        libmysqlclient15-dev mysql-client-5.0 mysql-common
    
    sudo apt-get install libmysql++-dev
    
    sudo gem install mysql
    

    0 讨论(0)
  • 2021-01-02 09:28

    If you are running Rails 3 you should use the mysql2 gem. You can install it with:

    gem install mysql2
    

    You will need to first install MySQL and any development headers. This will vary across different operating systems. On Ubuntu, you can run:

    aptitude install mysql-server 
    aptitude install mysql-client
    aptitude install mysql-common
    aptitude install libmysql-ruby
    aptitude install libmysqlclient-dev
    

    If you are creating a new project, use:

    rails new sample --database=mysql
    cd sample
    bundle install
    

    For more details, check out the project repository.

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