简体   繁体   中英

Issue with mysql gem on Ruby 1.9.2 on Mac OS X 10.6.6

I'm a Ruby noob (Roob?), and I'm trying to get my system up and running. I've gotten Ruby installed through rvm (used the Pragmatic instructions). I've also got MySQL installed via the Community Release (5.5.10). I've also got the mysql gem installed for Ruby (2.8.1).

In IRB, when I type:

require "mysql"

I get "true"

However, if I try to connect to my database, using this in IRB:

dbh = Mysql.real_connect("localhost", "root", "", "test")

I get this msg:

NoMethodError: undefined method real_connect' for Mysql:Class from (irb):2 from /Users/tlee/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in '

It doesn't appear that the Ruby mysql gem is installed correctly, or at least it doesn't appear to be communicating properly with the mysql instance. Any ideas on what the problem could be?

I've had some really strange problems with the mysql gem using Ruby 1.9.2.

Then I switched to the mysql2 gem, which solved most of my problems.

Here is an example (From the MySQL2 Readme):

client = Mysql2::Client.new(:host => "localhost", :username => "root")
results = client.query("SELECT * FROM users WHERE group='githubbers'")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM