76

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?

3
  • "included into Gemfile by default"? I don't see that in 3.2.8
    – KMC
    Sep 20, 2012 at 2:58
  • @KMC, year ago it was included? :)
    – fl00r
    Sep 20, 2012 at 8:28
  • 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. Apr 9, 2013 at 11:23

2 Answers 2

82

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.

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.

2
  • 8
    More features? Last I checked it can't even do prepared statements!
    – wmarbut
    Nov 30, 2012 at 16:33
  • I am also surprised there is no prepared statement support, although it looks like it's almost there as of five days ago.
    – twelve17
    Jul 30, 2013 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.