class
v3.0.9 - Show latest stable - Superclass: AbstractAdapter

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 http://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.

  • :encoding - (Optional) Sets the client encoding by executing “SET NAMES <encoding>” after connection.

  • :reconnect - Defaults to false (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html).

  • :sslca - Necessary to use MySQL with an SSL connection.

  • :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.

Constants

ADAPTER_NAME = 'MySQL'.freeze

LOST_CONNECTION_ERROR_MESSAGES = [\n"Server shutdown in progress",\n"Broken pipe",\n"Lost connection to MySQL server during query",\n"MySQL server has gone away" ]

NATIVE_DATABASE_TYPES = {\n:primary_key => "int(11) DEFAULT NULL auto_increment PRIMARY KEY".freeze,\n:string => { :name => "varchar", :limit => 255 },\n:text => { :name => "text" },\n:integer => { :name => "int", :limit => 4 },\n:float => { :name => "float" },\n:decimal => { :name => "decimal" },\n:datetime => { :name => "datetime" },\n:timestamp => { :name => "datetime" },\n:time => { :name => "time" },\n:date => { :name => "date" },\n:binary => { :name => "blob" },\n:boolean => { :name => "tinyint", :limit => 1 }\n}

QUOTED_FALSE = '1'.freeze, '0'.freeze

Files

  • activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

1Note

Compiling mysql gem in Leopard with MacPorts MySQL

crishoj · Nov 6, 20081 thank

Needs architecture and reference to mysql_config:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- \\
--with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config