What the Difference Between MySQL and MySQL2 Gem

What the difference between mysql and mysql2 gem

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.

What is the difference between MySQL & MySQL2 considering NodeJS

This is just 2 different APIs written by regular people. Difference is in syntax of commands and maybe in performance, just install both, make your own tests for your goals and choose one you think is more suitable for you.

Here is a comparison by NPMCompare:

What the difference between mysql and ruby-mysql gem

mysql is offered as gem for easy installation using RubyGems. It wraps unmodified tmtm's mysql-ruby extension into a proper gem. Please note that tmtm (Tomita Mashahiro) has deprecated development of this extension and only update it for bug fixes.

Read definition of mysql gem, and ruby-mysql gem.

Read difference from mysql, and mysql2 from this link.

What is mysql2?

mysql2 is the modern successor of the mysql gem. Don't worry, this will work fine for all current MySQL versions.

More here: Ruby, Rails: mysql2 gem, does somebody use this gem? Is it stable?

Ruby, Rails: mysql2 gem, does somebody use this gem? Is it stable?

mysql2 is meant as a more modern replacement for the existing mysql gem, which has been stale for a while now. I also heard that the author isn't supporting it anymore and instead recommends everyone use his pure-ruby version since it's compatible with more Ruby implementations (but is much slower).

The first issue with the mysql gem is it doesn't do any type casting in C, it gives you back ruby strings which you then have to convert into proper ruby types. Doing that in pure-ruby is extremely slow, and creates objects on the heap that never needed to existing in the first place. And as we all know, Ruby's GC is it's primary reason for it's slowness. So it's best to avoid it and do as much in pure C as you can.

Second is that it blocks the entire ruby VM while connecting, sending queries and waiting for responses, and even closing the connection. mysqlplus definitely helps with this issue, but only for sending queries as far as I know.

mysql2 aims to solve these problems while keeping the API extremely simple. Eric Wong (author of Unicorn) has contributed some awesome patches that make nearly everything non-blocking and/or release the GVL in Ruby. The Mysql2::Result class implements Enumerable so if you know how to use an Array, you know how to use it.

I'm only aware of a few people using it in production right now but it is being evaluated at Twitter, WorkingPoint and UserVoice too.

I'm also in talks with Yehuda about it being the recommended/default for Rails 3 when it ships. Some of its techniques and optimizations are also going to be brought into DataObjects' do_mysql driver soon as well.

The ActiveRecord driver should be pretty solid at the moment. All you should need to do is have the gem installed, and change your adapter name in database.yml to mysql2.

If you're interested in using it, give it a try. I'm quick to push fixes if you find any issues ;)

Switch mysql to mysql2 gem cause all unicode to mess up

My solution is to dump the data into a .sql file, use a unicode converter to convert that .sql file to proper encoding and then dump it back to the server.



Related Topics



Leave a reply



Submit