The MySQL adapter will work with both Ruby/MySQL, which is a Ruby-based MySQL adapter that comes bundled with Active Record, and with the faster C-based MySQL/Ruby adapter (available both as a gem and from www.tmtm.org/en/mysql/ruby/).

Options:

  • :host — Defaults to localhost
  • :port — Defaults to 3306
  • :socket — Defaults to /tmp/mysql.sock
  • :username — Defaults to root
  • :password — Defaults to nothing
  • :database — The name of the database. No default, must be provided.
  • :sslkey — Necessary to use MySQL with an SSL connection
  • :sslcert — Necessary to use MySQL with an SSL connection
  • :sslcapath — Necessary to use MySQL with an SSL connection
  • :sslcipher — Necessary to use MySQL with an SSL connection

By default, the MysqlAdapter will consider all columns of type tinyint(1) as boolean. If you wish to disable this emulation (which was the default behavior in versions 0.13.1 and earlier) you can add the following line to your environment.rb file:

  ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false
Methods
Constants
LOST_CONNECTION_ERROR_MESSAGES = [ "Server shutdown in progress", "Broken pipe", "Lost connection to MySQL server during query", "MySQL server has gone away"
Public Class methods
new(connection, logger, connection_options, config)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 150
150:       def initialize(connection, logger, connection_options, config)
151:         super(connection, logger)
152:         @connection_options, @config = connection_options, config
153: 
154:         connect
155:       end
Public Instance methods
active?()

CONNECTION MANAGEMENT ====================================

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 215
215:       def active?
216:         if @connection.respond_to?(:stat)
217:           @connection.stat
218:         else
219:           @connection.query 'select 1'
220:         end
221: 
222:         # mysql-ruby doesn't raise an exception when stat fails.
223:         if @connection.respond_to?(:errno)
224:           @connection.errno.zero?
225:         else
226:           true
227:         end
228:       rescue Mysql::Error
229:         false
230:       end
current_database()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 322
322:       def current_database
323:         select_one("SELECT DATABASE() as db")["db"]
324:       end
disconnect!()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 237
237:       def disconnect!
238:         @connection.close rescue nil
239:       end
quote(value, column = nil)

QUOTING ==================================================

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 185
185:       def quote(value, column = nil)
186:         if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
187:           s = column.class.string_to_binary(value).unpack("H*")[0]
188:           "x'#{s}'"
189:         elsif value.kind_of?(BigDecimal)
190:           "'#{value.to_s("F")}'"
191:         else
192:           super
193:         end
194:       end
quoted_false()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 208
208:       def quoted_false
209:         "0"
210:       end
quoted_true()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 204
204:       def quoted_true
205:         "1"
206:       end
reconnect!()
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 232
232:       def reconnect!
233:         disconnect!
234:         connect
235:       end
rename_table(name, new_name)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb, line 358
358:       def rename_table(name, new_name)
359:         execute "RENAME TABLE #{name} TO #{new_name}"
360:       end