title: How do I use Ruby to connect to a MySql database outside of Rails as a scripting language
body: <p>Hi Im using Ruby as a scripting language. Not for web development, but to connect to a local database on my computer and manipulate it.</p>
  
  <p>Id like to know how I can connect. Do I need to download/import tools? What do I need to get started?</p>
  
  <p>Thanks,</p>
  
  <hr>
  
  <p>Update</p>
  
  <p>I did gem install mysql2 and ran the following ruby file</p>
  
  <pre><code>require 'mysql2'  
  
  #my = Mysql.new(hostname, username, password, databasename)  
  con = Mysql.new('localhost', 'nverma', 'something', 'ruby')  
  rs = con.query('select * from contacts')  
  rs.each_hash { |h| puts h['name']}  
  con.close
  </code></pre>
  
  <p>and got the following error:-</p>
  
  <pre><code>/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext
   /kernel_require.rb:55:in `require': dlopen(/Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2 
   /mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
   Referenced from: /Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2/mysql2.bundle
   Reason: image not found - /Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2/mysql2.bundle
   from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext 
   /kernel_require.rb:55:in `require'
   from /Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `&lt;top (required)&gt;'
   from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext
   /kernel_require.rb:135:in `require'
   from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext
   /kernel_require.rb:135:in `rescue in require'
   from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext
   /kernel_require.rb:144:in `require'
   from sol5.rb:1:in `&lt;main&gt;'
  </code></pre>
  
  <p>Please help!</p>