0

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?

4 Answers 4

3

How about

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

?

Sign up to request clarification or add additional context in comments.

5 Comments

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

reinstall mysql with command

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-include=/usr/local/mysql/include

i've found the solution here http://thinlight.org/2010/05/12/how-to-install-ruby-mysql-on-mac-os-x-10-6-snow-leopard/

Comments

1

I faced the same problem. Uninstalling mysql gem and installing ruby-mysql solved the issue.

sudo gem uninstall mysql

sudo gem install ruby-mysql

Comments

0

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

2 Comments

nah, that did not work either generate.rb:37: undefined method `real_connect' for Mysql:Class (NoMethodError) maybe i should reinstall everything, seems like i am missing a lot of stuff
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.