class
rails latest stable - Superclass: AbstractAdapter

Class deprecated or moved

This class is deprecated or moved on the latest stable version. The last existing version (v4.2.9) is shown here.

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).

  • :strict - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/sql-mode.html)

  • :variables - (Optional) A hash session variables to send as SET @@SESSION.key = value on each database connection. Use the value :default to set a variable to its DEFAULT value. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/set-statement.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

ENCODINGS = {\n"armscii8" => nil,\n"ascii" => Encoding::US_ASCII,\n"big5" => Encoding::Big5,\n"binary" => Encoding::ASCII_8BIT,\n"cp1250" => Encoding::Windows_1250,\n"cp1251" => Encoding::Windows_1251,\n"cp1256" => Encoding::Windows_1256,\n"cp1257" => Encoding::Windows_1257,\n"cp850" => Encoding::CP850,\n"cp852" => Encoding::CP852,\n"cp866" => Encoding::IBM866,\n"cp932" => Encoding::Windows_31J,\n"dec8" => nil,\n"eucjpms" => Encoding::EucJP_ms,\n"euckr" => Encoding::EUC_KR,\n"gb2312" => Encoding::EUC_CN,\n"gbk" => Encoding::GBK,\n"geostd8" => nil,\n"greek" => Encoding::ISO_8859_7,\n"hebrew" => Encoding::ISO_8859_8,\n"hp8" => nil,\n"keybcs2" => nil,\n"koi8r" => Encoding::KOI8_R,\n"koi8u" => Encoding::KOI8_U,\n"latin1" => Encoding::ISO_8859_1,\n"latin2" => Encoding::ISO_8859_2,\n"latin5" => Encoding::ISO_8859_9,\n"latin7" => Encoding::ISO_8859_13,\n"macce" => Encoding::MacCentEuro,\n"macroman" => Encoding::MacRoman,\n"sjis" => Encoding::SHIFT_JIS,\n"swe7" => nil,\n"tis620" => Encoding::TIS_620,\n"ucs2" => Encoding::UTF_16BE,\n"ujis" => Encoding::EucJP_ms,\n"utf8" => Encoding::UTF_8,\n"utf8mb4" => Encoding::UTF_8,\n}

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