安装适用于 Ruby 的 MySQL2 适配器

发布于 2024-11-04 20:05:15 字数 1010 浏览 1 评论 0原文

我在连接到 MySQL 时遇到一些错误,修复它后我升级了 mysql2 gem。

我运行此命令来安装 mysql2:

ruby install mysql2

现在“gem list”显示此 gem: mysql2 (0.3.2)

但我认为它仍然不是我的应用程序环境的一部分,因为服务器给出了此错误:

Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter)

我有 RVM,并且使用捆绑器为此应用程序制作 gemset。如何将 mysql2 添加到该应用程序的 gemset 中?

这是我的 gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.7'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

gem 'mysql2' , '0.3.2' 

这是我的 MySQL 适配器版本:

$bundle show mysql2
/home/agenadinik/workspace/udfr/mysql2/ruby/1.9.1/gems/mysql2-0.3.2

另外

$ rvm gemdir /home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin/gem:4:警告:路径中不安全的世界可写目录 /home/agenadinik,模式 040777 /home/agenadinik/.rvm/gems/ruby-1.9.2-p180

I am getting some errors whilst connecting to MySQL and the fixing of it led me to upgrade the mysql2 gem.

I ran this command to install mysql2:

ruby install mysql2

and now "gem list" shows this gem: mysql2 (0.3.2)

But I think it isn't part of my application environment still since the server gives this error:

Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter)

I have RVM and I've used bundler to make a gemset for this application. How can I add mysql2 to this application's gemset?

This is my gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.7'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

gem 'mysql2' , '0.3.2' 

And this is my MySQL adapter version:

$bundle show mysql2
/home/agenadinik/workspace/udfr/mysql2/ruby/1.9.1/gems/mysql2-0.3.2

Also

$ rvm gemdir
/home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin/gem:4: warning: Insecure world writable dir /home/agenadinik in PATH, mode 040777
/home/agenadinik/.rvm/gems/ruby-1.9.2-p180

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满栀 2024-11-11 20:05:15

请注意,您不能将 mysql2 版本 0.3.x 与低于 3.1.x 的 Rails 版本一起使用。
我假设您使用的是 Rails 3.0.x 或更低版本(因此您需要使用 mysql2 版本 0.2.x):

以下是如何设置 gemset 和 Gemfile 以使用 mysql2 的示例:

~/code/myapp $ rvm gemset create myapp
~/code/myapp $ rvm use @myapp
<<<<<Edit the Gemfile and add the line gem "mysql2","0.2.7" then save and exit editor.>>>>>
~/code/myapp $ bundle install
~/code/myapp $ bundle show mysql2
<<<<<Output should be similar to: /home/<your-name>/.rvm/gems/ruby-<some-version>@myapp/gems/mysql2-0.2.7>>>>>

Note that you cannot use mysql2 version 0.3.x with Rails version less than 3.1.x.
I assume you are using Rails 3.0.x or below (and thus you need to use mysql2 version 0.2.x):

Here is an example of how to set up a gemset and the Gemfile to use mysql2:

~/code/myapp $ rvm gemset create myapp
~/code/myapp $ rvm use @myapp
<<<<<Edit the Gemfile and add the line gem "mysql2","0.2.7" then save and exit editor.>>>>>
~/code/myapp $ bundle install
~/code/myapp $ bundle show mysql2
<<<<<Output should be similar to: /home/<your-name>/.rvm/gems/ruby-<some-version>@myapp/gems/mysql2-0.2.7>>>>>
暖心男生 2024-11-11 20:05:15

如果您使用 Bundler,则应添加

gem "mysql2"

Gemfile 中,然后运行 ​​bundle install

If you're using Bundler, you should add

gem "mysql2"

to your Gemfile, then run bundle install

慕巷 2024-11-11 20:05:15

在 Rails >= 3.2.0 上,如果您使用旧版本的捆绑器,您将会看到这一点。将捆绑程序更新为 >= 1.1.1:

gem update bundler

完成此操作后,更新您的 gem:

bundle install

On Rails >= 3.2.0 you will see this if you are using an older version of bundler. Update bundler to >= 1.1.1:

gem update bundler

Once you have done this, update your gems:

bundle install
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文