mysql2 gem is a simple and fast Mysql library for Ruby. And, this tutorial shows how to perform transactions using mysql2 gem.
seen from Russia

seen from Malaysia
seen from Malaysia
seen from Germany
seen from China
seen from China

seen from United States

seen from Montenegro
seen from United States

seen from Hong Kong SAR China

seen from Malaysia
seen from Singapore
seen from United States

seen from Malaysia
seen from Montenegro

seen from United States
seen from United States

seen from United States

seen from United States

seen from United States
mysql2 gem is a simple and fast Mysql library for Ruby. And, this tutorial shows how to perform transactions using mysql2 gem.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
mysql2 gem is a simple and fast Mysql library for Ruby. And, this tutorial shows how to use the select query to interact with the MySQL Serv
mysql2 gem is a simple and fast Mysql library for Ruby. And, this tutorial shows how to perform transactions using mysql2 gem.
mysql2 gem is a simple and fast Mysql library for Ruby. And, this tutorial shows how to use the prepared statements using mysql2 gem.
mysql2 gem is a simple and fast Mysql library for Ruby. And, this tutorial shows how to use the select query to interact with the MySQL Server using mysql2 gem.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
The three MySQL Gems of Ruby
In the beginning there was nothing.
So God decided to create three different MySQL gems in order to prove all ruby developers.
1) Gem "mysql"
This is the "classical" MySQL gem. It does basically everything and it does it nicely.
Unless you hit the UTF-8 barrier.
2) Gem "mysql2"
This is the gem, which is used by Rails by default. It will do escaping, it will do UTF-8, it will do much for you.
But it is unable to do prepared statements.
3) Gem "ruby-mysql"
This is a very unknown gem, but it can do basically everything: escaping, UTF-8, prepared statements, reconnects - you name it.
If you really need all those features, I'd suggest you to give it a try. Otherwise mysql2 is the way to go.
The only problem is that its documentation is Korean. But you'll find out, that the syntax of the mysql gem simply applies.
And also Google Translator helps.
bundleで入ったっぽいgem listで表れないgemを消す
# bundle exec gem uninstall mysql2
などとするとgemが消えるが、依存しているライブラリがあることに注意をすること。例えば、mysql2とか消すとrakeやrailsが軒並みコマンド通らなくなるので、アダプタを変更するか、bundle installまたはbundle updateをして入れなおすことになる。
SQL: Structured Query Language or as my dog would say, woof.
SQL, you see it used everywhere. From high school grading systems to high finance. Lets see how it can fit in with Ruby. To install it in your Terminal: gem install mysql2 We're going to learn how to use it from the ground up. By the way... do you like dogs? Good, because that's the metaphor of this post. Like any typical Ruby Gem, list it at the top of your code. #red txt yello txt require 'mysql2' Lets connect the client side (web browser, user computer, etc) to our SQL server (where the magic happens). client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "dogs") How many dogs do we have in the SQL pound? We're working on the Ruby side of the house, so first we need to create a string to send from the Client to the Server. results = client.query(" ") OK, now we can put in our SQL query, results = client.query("SELECT * FROM dogs") results.count => 3 What type of output are we getting? # Our results from issuring a query gives us a Mysql2::Result object. Where is your puppy? Our results can be read like a hash. So we'll go cage by cage to find you a puppy. results = client.query("SELECT * FROM dogs") results.each do | cage | puts cage end => {"dog_id"=>1, "dog_name"=>"Stark", "color"=>"grey"} {"dog_id"=>2, "dog_name"=>"PuppyLove", "color"=>"blue"} {"dog_id"=>3, "dog_name"=>"Lannister", "color"=>"red"} We can make more direct shout outs to our dogs. results = client.query("SELECT * FROM dogs WHERE dog_id=2").each do |best_dog| # while in this do loop, the results are in hash form best_dog end Think results always stay as a hash? Prepare to be fooled. results.class #=> Array results[0] #=> {"dog_id"=>2, "dog_name"=>"PuppyLove", "color"=>"blue"} Using an Array makes sense. It will store your results if your query gets back multiple results. Did you want to save a particular element? favorite = "Unknown" results = client.query("SELECT * FROM dogs WHERE dog_id=2").each do |best_dog| # while in this do loop, the results are in hash form # we can now search for dogs with a particular criteria, and get their names. # in this case its the name of the second dog. # since its a hash we can save the a particular value as we would normally. favorite = best_dog["dog_name"] end puts favorite #=> PuppyLove