Skip to content

Instantly share code, notes, and snippets.

@sathlan
Last active August 29, 2015 14:12
Show Gist options
  • Save sathlan/e5af4d265cf7e34e585d to your computer and use it in GitHub Desktop.
Save sathlan/e5af4d265cf7e34e585d to your computer and use it in GitHub Desktop.
OPT_PROTOCOL difficulty in mysql-gem.
#!/opt/chef/embedded/bin/ruby
require 'mysql'
require 'optparse'
options = {:localhost => '127.0.0.1'}
OptionParser.new do |opts|
opts.on("-l", "Use localhost instead of 127.0.0.1") do |l|
options[:localhost] = 'localhost'
end
end.parse!
connection = ::Mysql.init
connection.options(::Mysql::OPT_PROTOCOL, 1)
connection.connect(
options[:localhost],
'test_user',
'user_passwd',
nil,
3306,
nil
)
connection.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment