0
votes

I'm a newbie to ruby, trying to connect mysql servcer through Ruby for cucumber and getting the following error while running cukes. error: no such file to load -- mysql (LoadError)

But installed mysql gem and here is my gem list and also has libmysql.dll under ruby_home\bin path

  • addressable (2.2.8)
  • builder (3.0.0)
  • bundler (1.1.4)
  • childprocess (0.3.3)
  • cucumber (1.2.1)
  • diff-lcs (1.1.3)
  • ffi (1.0.11, 1.0.9 x86-mingw
  • gherkin (2.11.1 x86-mingw32)
  • headless (0.2.2)
  • json (1.7.3)
  • libwebsocket (0.1.4)
  • minitest (1.6.0)
  • multi_json (1.3.6)
  • mysql (2.8.1 x86-mingw32)
  • mysql2 (0.3.11 x86-mingw32)
  • net-ldap (0.3.1)
  • rake (0.8.7)
  • rdoc (2.5.8)
  • rspec (2.10.0)
  • rspec-core (2.10.1)
  • rspec-expectations (2.10.0)
  • rspec-mocks (2.10.1)
  • rubygems-update (1.8.24)
  • rubyzip (0.9.9)
  • selenium-webdriver (2.24.0)
  • titleize (1.2.1)
  • watir-webdriver (0.6.1)

Any idea whats going on...

1
Any idea what's going on here? - TP_JAVA

1 Answers

2
votes

What version of Ruby are you running mate? If you're running 1.8 you need to add "require 'rubygems'" before your "require 'mysql'. If not then try requiring the gem in a non-explicit way. Something like this:

require_relative "rubygems"    
require_relative "mysql"

If you want to give it a quick test use this code below..:

require "rubygems"   

require "mysql"

     begin

     # connect to the MySQL server

     db = Mysql.real_connect("localhost", "username", "password")


     # get server version string and display it

     puts "Server version: " + db.get_server_info


   rescue Mysql::Error => e

     puts "Error code: #{e.errno}"

     puts "Error message: #{e.error}"

     puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")

   ensure

     # disconnect from server

     db.close if db

   end

If all goes well you should see your mysql version..