What the difference between mysql and mysql2 gem
Asked Answered
G

2

77

I used to work with the mysql gem, but often nowadays I hear about the mysql2 gem. Also, it is included in the Gemfile by default in Rails 3.0.x.

What is the difference and advantages of using the mysql2 gem?

Gerhardt answered 23/3, 2011 at 20:59 Comment(3)
"included into Gemfile by default"? I don't see that in 3.2.8Intend
@KMC, year ago it was included? :)Gerhardt
I too am after a differences list, I hit one diff that was answered elsewhere re each_hash being removed. It would be nice to know what other changes I should search my code base for.Nuzzi
C
83

Here's a quote from the mysql2 gem page:

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.

Cowes answered 23/3, 2011 at 21:11 Comment(0)
D
12

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.

Disk answered 23/3, 2011 at 21:20 Comment(2)
More features? Last I checked it can't even do prepared statements!Blakeney
I am also surprised there is no prepared statement support, although it looks like it's almost there as of five days ago.Keciakeck

© 2022 - 2024 — McMap. All rights reserved.