tags:

views:

36

answers:

2

I setup ruby and mysql on my mac and i am having issues connecting to my local mysql server.

require 'rubygems'
require 'mysql'
...    
db = Mysql.new("localhost", "root", "", "")
...

This would give me the following error when i run this script fromt he command line:

generate.rb:37:in `initialize': wrong number of arguments (4 for 0) (ArgumentError)
from generate.rb:37:in `new'
from generate.rb:37

I have no idea why i am getting this error...any ideas?

+1  A: 

How about

db = Mysql.connect("localhost", "root", "", "")

?

Jonas Elfström
that gives:generate.rb:37: undefined method `connect' for Mysql:Class (NoMethodError)
gprime
Hmm, I wonder what MySQL connector you are using. What does `sudo gem spec mysql` say?
Jonas Elfström
lenny:script gprime$ sudo gem spec mysqlPassword:--- !ruby/object:Gem::Specification name: mysqlversion: !ruby/object:Gem::Version hash: 45 prerelease: false segments: - 2 - 8 - 1 version: 2.8.1platform: rubyauthors: - TOMITA Masahiroautorequire: bindir: bincert_chain: []...
gprime
That makes in even more strange because according to http://www.tmtm.org/en/mysql/ruby/ there really should be a connect method on Mysql.
Jonas Elfström
Also it seems Masahiro has moved to github http://github.com/tmtm/ruby-mysql#readme but it also seems lack english documentation.
Jonas Elfström
A: 

You have clear message about wrong number of arguments to new method. Maybe try different method? real_connect for example.

db = Mysql.real_connect('localhost', 'test', 'test', 'testdb');

user: test, pass: test, db: testdb

Casual Coder
nah, that did not work eithergenerate.rb:37: undefined method `real_connect' for Mysql:Class (NoMethodError)maybe i should reinstall everything, seems like i am missing a lot of stuff
gprime
require 'mysql' is passing so module is loaded, at least it seems that way. Odd. I tested that example and it worked for me (of course different credentials but it is irrelevant).
Casual Coder