Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Cast connection options to correct datatype. #313

merged 1 commit into from

3 participants

drn commented

In order to set database connection options on Heroku using the Amazon RDS add-on, we need to specify the connection options via the DATABASE_URL as such:


However, these connection options are interpreted as strings when initializing the mysql2 client which results in failures like:

2012-10-04T23:13:05+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.12b4/lib/mysql2/client.rb:26:in `connect_timeout=': wrong argument type String (expected Fixnum) (TypeError)
2012-10-04T23:13:05+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.12b4/lib/mysql2/client.rb:26:in `block in initialize'
2012-10-04T23:13:05+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.12b4/lib/mysql2/client.rb:24:in `each'
2012-10-04T23:13:05+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.12b4/lib/mysql2/client.rb:24:in `initialize'

This pull casts the connection option values to the desired types.

@brianmario brianmario merged commit 3385de3 into brianmario:master

1 check failed

Details default The Travis build failed

thanks! don't worry about that travis failure - it's something unrelated while trying to build on ruby-head.

drn commented

cool :)


Nice patch. I'm giving myself a facepalm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 4, 2012
  1. Cast connection options to correct datatype.

    darrenli committed
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/mysql2/client.rb
9 lib/mysql2/client.rb
@@ -23,7 +23,14 @@ def initialize(opts = {})
# Set MySQL connection options (each one is a call to mysql_options())
[:reconnect, :connect_timeout, :local_infile, :read_timeout, :write_timeout].each do |key|
next unless opts.key?(key)
- send(:"#{key}=", opts[key])
+ case key
+ when :reconnect, :local_infile
+ send(:"#{key}=", !!opts[key])
+ when :connect_timeout, :read_timeout, :write_timeout
+ send(:"#{key}=", opts[key].to_i)
+ else
+ send(:"#{key}=", opts[key])
+ end
# force the encoding to utf8
Something went wrong with that request. Please try again.