def initialize(opts = {})
@query_options = @@default_query_options.dup
@query_options.merge! opts
init_connection
[:reconnect, :connect_timeout].each do |key|
next unless opts.key?(key)
send("#{key}=""#{key}=", opts[key])
end
self.charset_name = opts[:encoding] || 'utf8'
@read_timeout = opts[:read_timeout]
if @read_timeout and @read_timeout < 0
raise Mysql2::Error, "read_timeout must be a positive integer, you passed #{@read_timeout}"
end
ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher))
user = opts[:username]
pass = opts[:password]
host = opts[:host] || 'localhost'
port = opts[:port] || 3306
database = opts[:database]
socket = opts[:socket]
flags = opts[:flags] ? opts[:flags] | @query_options[:connect_flags] : @query_options[:connect_flags]
connect user, pass, host, port, database, socket, flags
end