Created
December 23, 2011 13:04
-
-
Save flackou/1514154 to your computer and use it in GitHub Desktop.
Testing mysql2 wait_timeout param
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
gem 'mysql2' | |
gem 'activerecord', '3.1.1' | |
require 'active_record' | |
# http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout | |
MYSQL_WAIT_TIMEOUT_MAX = 2147483 | |
# Testing the remote db connection after a 60s sleep | |
def test_connection(extra_conf = {}) | |
conf = { | |
:host => "1.2.3.4", | |
:username => "root", | |
:database => "test", | |
:adapter => "mysql2" | |
} | |
ActiveRecord::Base.establish_connection(conf.merge(extra_conf)) | |
puts ActiveRecord::Base.connection.execute("SHOW VARIABLES LIKE \"wait_timeout\"").to_a.join(" : ") | |
sleep 60 | |
puts ActiveRecord::Base.connection.active? ? "Connection up !" : "Connection lost !" | |
end | |
test_connection(:wait_timeout => MYSQL_WAIT_TIMEOUT_MAX) | |
test_connection(:wait_timeout => MYSQL_WAIT_TIMEOUT_MAX + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby mysql2_wait_timeout.rb | |
wait_timeout : 2147483 | |
Connection up ! | |
wait_timeout : 2147484 | |
Connection lost ! |
hi guys,
just one more little discovery,
this has been fixed in mysql 5.6
link? re: mysql 5.6 fix
No particular link.just install MySQL 5.6 which has been released a while ago.
In production systems I will stick with 5.1
Please mind that the actual limit for wait_timeout
depends on the operating system you are using. The individual values can be retrieved from the MySQL documentation (links v.5.6).
Another point is that I cannot find wait_timeout
in Rails 3.2.14 while there are configuration options in Rails 4. I wonder if I am actually able to pass the setting via database.yml
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm having this same issue. Anyone that has success to fix that?