Problems using the Mysql gem

Discussion in 'Ruby' started by Jim Burgess, Sep 6, 2010.

  1. Jim Burgess

    Jim Burgess Guest

    Hi,

    I'm using the mysql (2.8.1 x86-mingw32) gem and MySQL Server version
    5.0.90 on Windows 7, 64 bit. I'm also using ruby 1.8.7.

    When I run the following script (replacing user name and password
    appropriately)

    require "rubygems"
    require "mysql"
    dbh = Mysql.real_connect("localhost", "user", "pass", "test")
    puts "Server version: " + dbh.get_server_info
    dbh.close

    I get the following error message:

    /test.rb:3: uninitialized constant Mysql (NameError)
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in
    `gem_original_require'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in
    `require'
    from mysql.rb:2
    >Exit code: 1


    Can anyone give me a pointer as to what is going wrong?
    I have tried googling the error message, but with no luck.
    I have also read the documentation installed with the gem and as far as
    I can tell I am using the correct syntax.

    Thanks in advance.
    --
    Posted via http://www.ruby-forum.com/.
     
    Jim Burgess, Sep 6, 2010
    #1
    1. Advertising

  2. Jim Burgess

    Luis Lavena Guest

    On Sep 6, 6:27 am, Jim Burgess <> wrote:
    > Hi,
    >
    > I'm using the mysql (2.8.1 x86-mingw32) gem and MySQL Server version
    > 5.0.90 on Windows 7, 64 bit. I'm also using ruby 1.8.7.
    >


    Is MySQL installed in 64bits? Or is 32bits MySQL?

    Please note that MySQL binary needs a 32bits version of MySQL 5.0
    "libmysql.dll"

    You can find more details about copying libmysql.dll or about
    compiling MySQL gem for 5.1 in RubyInstaller tutorial page:

    http://github.com/oneclick/rubyinstaller/wiki/Tutorials

    > Can anyone give me a pointer as to what is going wrong?
    > I have tried googling the error message, but with no luck.
    > I have also read the documentation installed with the gem and as far as
    > I can tell I am using the correct syntax.
    >


    It might be that you don't have 32bits libmysql.dll somewhere in the
    PATH for Ruby to use.

    Placing a 32bits libmysql.dll in Ruby bin directory should help.

    --
    Luis Lavena
     
    Luis Lavena, Sep 6, 2010
    #2
    1. Advertising

  3. Jim Burgess

    Jim Burgess Guest

    Hi,

    Thanks for the replies.

    After much hair pulling and messing around with environment variables I
    finally figured out what was going wrong.

    It is quite embarrassing, but I'll post it here as it might help someone
    else.

    The problem was that I'd actually called the file I was working on
    'mysql.rb'.
    As the require 'mysql' line at the beginning of my code looks in the
    current directory first, my code was just including itself, and not the
    gem I wanted.
    Doh!

    Thanks again for your help.
    --
    Posted via http://www.ruby-forum.com/.
     
    Jim Burgess, Sep 7, 2010
    #3
  4. Jim Burgess

    annika

    Joined:
    Apr 3, 2014
    Messages:
    1
    Thank you so much!
    I did the same (called the file 'mysql.rb') :lol:
     
    annika, Apr 3, 2014
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Austin 7873
    Replies:
    5
    Views:
    205
    Eric Hodel
    Jan 27, 2007
  2. Mark Meijer

    mySQL Ruby Gem and MAMP mySQL

    Mark Meijer, Feb 2, 2008, in forum: Ruby
    Replies:
    3
    Views:
    214
    louis
    Feb 3, 2008
  3. Daniel Berger
    Replies:
    2
    Views:
    168
    Daniel Berger
    Sep 12, 2008
  4. Renato Jf
    Replies:
    3
    Views:
    135
    Luis Lavena
    Dec 15, 2009
  5. Geoff Rowell
    Replies:
    5
    Views:
    412
    Manish Nautiyal
    Aug 3, 2010
Loading...

Share This Page