mysql 和 mysql2 gem 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5411551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What the difference between mysql and mysql2 gem
提问by fl00r
I used to work with the mysql
gem, but often nowadays I hear about the mysql2
gem. Also, it is included in the Gemfileby default in Rails 3.0.x
.
我曾经使用过mysql
宝石,但现在我经常听说mysql2
宝石。此外,它默认包含在Gemfile中Rails 3.0.x
。
What is the difference and advantages of using the mysql2
gem?
使用mysql2
gem 有什么区别和优势?
回答by ALoR
Here's a quote from the mysql2 gem page:
这是mysql2 gem 页面的引用:
Yeah… but why?
Someone: Dude, the Mysql gem works fiiiiiine.
Me: It sure does, but it only hands you nil and strings for field values. Leaving you to convert them into proper Ruby types in Ruby-land - which is slow as balls.
Someone: OK fine, but do_mysql can already give me back values with Ruby objects mapped to MySQL types.
Me: Yep, but its API is considerably more complex and can be ~2x slower.
是的……但为什么呢?
某人:老兄,Mysql gem 可以正常工作。
我:确实可以,但它只会为您提供 nil 和字段值的字符串。让您在 Ruby-land 中将它们转换为正确的 Ruby 类型 - 这就像球一样慢。
某人:好的,但是 do_mysql 已经可以将 Ruby 对象映射到 MySQL 类型的值返回给我。
我:是的,但它的 API 复杂得多,而且速度可能慢 2 倍。
回答by Nikhil
mysql2 is very much faster than the mysql gem. Also, apart from being effective, it also has more features and is more fun, just like Ruby on Rails.
mysql2 比 mysql gem 快得多。而且,除了有效之外,它还具有更多功能,更有趣,就像 Ruby on Rails 一样。