Mysql ?

MySQL is an Oracle-backed open source relational database management system (RDBMS) based on Structured Query Language (SQL). MySQL runs on virtually all platforms, including Linux, UNIX and Windows. Although it can be used in a wide range of applications, MySQL is most often associated with web applications and online publishing.

Use Mysql with a Ruby on Rails application

Ensure the MySQL gem is defined in your Gemfile

gem ‘mysql2’


and bundle install


Create a new MySQL database for a Rails application

Use MySQL gem with Ruby only

You can follow this quick tutorial to use MySQL gem with Ruby (without Rails framework) :


      require 'mysql'
      begin
         # connect to the MySQL server
         dbh = Mysql.real_connect("localhost", "user", "pass", "bdd_name")
         res = dbh.query("SELECT field1, field2 FROM table WHERE field3 = '1' LIMIT 100") # max 100
         while row = res.fetch_row do
             printf "%s, %s\n", row[0], row[1]
             update = dbh.prepare "UPDATE table SET field4 = ? WHERE field1 = ? AND field2 = ?"
             update.execute 1, row[0], row[1] 
         end
      rescue Mysql::Error => e
         puts "Error code: #{e.errno}"
         puts "Error message: #{e.error}"
         puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
      ensure
         # disconnect from server
         dbh.close if dbh
      end