Ruby Gem adaptor MySQL error

42 Views Asked by At

I am getting the below error while using the MySQL gem; Tried mysql2 and it also gives the same error.

-bash-4.1$ gem list

*** LOCAL GEMS ***

mysql (2.9.1)

-bash-4.1$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]


-bash-4.1$ irb
irb(main):001:0> require 'mysql'
NameError: uninitialized constant Mysql
    from ./mysql.rb:10
    from (irb):1:in `require'
    from (irb):1
    from :0
irb(main):002:0> 

Please let me know if there is a solution for this; thanks!

2

There are 2 best solutions below

0
nattfodd On

Are you using bundler/rvm? If so, start irb with:

bundle exec irb
0
slal On

make sure you are in the right gemset and ruby version from where you are accessing the gem. Before typing in the irb, check what gemset you are in:

rvm gemset list

then check the gems installed in that particular gemset

rvm <my-gemset-name> do gem list

If they do not match, that is your problem and you can fix it by changing to the right gemset:

 rvm use <my-gemset>

Similarly, check for ruby version, i.e if the ruby version for your installed gem and from where you are running your irb match