简体   繁体   English

当我通过 rvm 使用 rails3 时,如何在 ubuntu 上安装 mysql2 gem?

[英]How do I install the mysql2 gem on ubuntu, when I'm using rails3 via rvm?

I'm trying to figure my way around the vastly complex maze that is rails configuration.我正试图绕过作为导轨配置的极其复杂的迷宫。 So far, I'm managed to set up rvm on ubuntu (for some reason, ruby is outdated in the ubuntu repo's).到目前为止,我已经设法在 ubuntu 上设置了 rvm(由于某种原因,ruby 在 ubuntu 存储库中已过时)。 I've managed to set up a rails project.我设法建立了一个rails项目。 I want my test project to use mysql rather then mysqlite.我希望我的测试项目使用 mysql 而不是 mysqlite。

When I tried 'rake db:migrate', I got an error: ".:! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'"当我尝试 'rake db:migrate' 时,出现错误:“.:!缺少 mysql2 gem。将其添加到您的 Gemfile:gem 'mysql2'”

When I try 'gem install mysql', I get an error, telling me that I need to provide parameters to the installation command.当我尝试“gem install mysql”时,我收到一个错误,告诉我需要为安装命令提供参数。 However, the list of parameters is huge, and I have no idea which ones to select.但是,参数列表很大,我不知道 select 的参数列表。

How can I get rails3 via rvm running on ubuntu with mysql?如何通过 rvm 在 ubuntu 和 mysql 上运行获得 rails3?

Thanks.谢谢。

I had the same problem, all you need to do is to install the libmysqlclient-dev first.我有同样的问题,你需要做的就是先安装 libmysqlclient-dev。

cheers干杯

First, you need mysql installed.首先,您需要安装 mysql。 You can install it using Ubuntu's package manager.您可以使用 Ubuntu 的 package 管理器安装它。 No special steps needed.无需特殊步骤。 You also need to initially create your database and user using the mysql tool.您还需要使用 mysql 工具最初创建数据库和用户。 This link shows how to do that:此链接显示了如何做到这一点:

http://www.tutorialspoint.com/ruby-on-rails/rails-database-setup.htm http://www.tutorialspoint.com/ruby-on-rails/rails-database-setup.htm

Second, you need to have the mysql2 gem listed in your Gemfile.其次,您需要在 Gemfile 中列出 mysql2 gem。 This tells Rails to go ahead and use that gem.这告诉 Rails 提前 go 并使用该 gem。 You need a line like this:你需要这样的一行:

gem 'mysql2', '< 0.3'

I'm specifying the version to be less than 0.3 because I'm using Rails 3.0.7 and version 0.3 and higher are for Rails 3.1.我将版本指定为小于 0.3,因为我使用的是 Rails 3.0.7,而 0.3 及更高版本适用于 Rails 3.1。 Also, be sure to use the mysql2 gem and not mysql - it seems to handle character encoding better.此外,请务必使用 mysql2 gem 而不是 mysql - 它似乎可以更好地处理字符编码。

Third, run "bundle install" so Rails downloads and installs the mysql2 gem.第三,运行“bundle install”以便 Rails 下载并安装 mysql2 gem。

Lastly, you need to change your database.yml file to put in the connection information for your database like so:最后,您需要更改 database.yml 文件以放入数据库的连接信息,如下所示:

development:
  adapter:  mysql2
  database: your_database_name
  username: your_username
  password: your_password
  encoding: utf8

The encoding part is just what I'm using, you may need something different.编码部分正是我正在使用的,你可能需要一些不同的东西。 This entry tells Rails how to find your database in the development environment.这个条目告诉 Rails 如何在开发环境中找到你的数据库。

Once that's all in place, things should work.一旦一切就绪,一切就应该奏效了。

sudo apt-get install libmysql-ruby libmysqlclient-dev

If the above command does not work because libmysql-ruby cannot be found, the following should be sufficient:如果上面的命令因为找不到libmysql-ruby而不起作用,那么以下应该就足够了:

sudo apt-get install libmysqlclient-dev

On Red Hat/CentOS and other distributions using yum:在 Red Hat/CentOS 和其他使用 yum 的发行版上:

sudo yum install mysql-devel

On Mac OS X with Homebrew:在带有 Homebrew 的 Mac OS X 上:

brew install mysql

then run然后运行

bundle install

to install to gems as listed in gemfile安装到 gemfile 中列出的 gems

I believe you need to add gem name to your Gemfile, located in your projects root:我相信您需要将 gem 名称添加到位于项目根目录中的 Gemfile 中:

It should read something like this:它应该是这样的:

source 'http://rubygems.org'

gem 'rails', version
gem 'mysql', version

Where version is the the gem version you'd like to install, and will have a bunch of other information by default.其中 version 是您要安装的 gem 版本,默认情况下会有一堆其他信息。

Then, navigate to your project directory and run the bundle command and you should be set.然后,导航到您的项目目录并运行 bundle 命令,您应该已经设置好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ubuntu 12.04 - RubyOnRails - gem install mysql2似乎安装但是当我这样做时失败:gem mysql2 - 未知命令mysql2 - Ubuntu 12.04 - RubyOnRails - gem install mysql2 seems to install but fails when i do: gem mysql2 - Unknown command mysql2 尝试了许多建议,如何安装mysql2 gem? - Tried many suggestions, how do I install mysql2 gem? 使用rvm在Snow Leopard上为Rails 3安装mysql2 gem - Install mysql2 gem on Snow Leopard for Rails 3 with rvm 我得到“未能构建 gem 原生扩展”。 当我尝试安装 mysql2 (OSX) - I get "failed to build gem native extension." when I'm trying to install mysql2 (OSX) 无法在Lion,Rails3应用程序上使用mysql2 gem与MAMP2和RVM一起使用 - Can't get mysql2 gem to work with MAMP2 and RVM on Lion, Rails3 app Rails3 + mysql2 gem,我得到LibMYSQL.dll未找到错误 - Rails3 + mysql2 gem, I get LibMYSQL.dll not found error 捆绑安装将无法使用Ruby 1.9.3,Rails3和Mac Mountain Lion安装mysql2 gem - Bundle Install wont install mysql2 gem with Ruby 1.9.3, Rails3 and Mac Mountain Lion 如何在 Rails 中通过 Gemfile 安装 mysql2 - how to install mysql2 via Gemfile in Rails 无法在Ubuntu 14上安装mysql2 gem - Failed to install mysql2 gem on Ubuntu 14 在mac上安装带有rails3的mysql2 gem真的很奇怪 - Really weird error installing mysql2 gem with rails3 on mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM