Skip to content

Instantly share code, notes, and snippets.

@johanneswuerbach
Created October 15, 2012 19:19
Show Gist options
  • Save johanneswuerbach/3894559 to your computer and use it in GitHub Desktop.
Save johanneswuerbach/3894559 to your computer and use it in GitHub Desktop.
Test database connection
require "mysql"
require "json"
db_host = ""
db_user = ""
db_pass = ""
db_name = ""
# Test database conneciton
requests = 0
errors = 0
while true
requests += 1
begin
db = Mysql.init
db.options(Mysql::OPT_READ_TIMEOUT, 2)
db.real_connect(db_host, db_user, db_pass, db_name)
db.query("SHOW TABLES")
puts "DB: OK (#{errors} / #{requests})"
rescue Mysql::Error => err
errors += 1
puts "DB: Error (#{errors} / #{requests})"
end
sleep 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment