PDA

View Full Version : Ruby MySQL access problem


harkerboy
April 20th, 2006, 07:40 PM
I've got the following code seems runnable
# dbConn.rb

require "mysql"

begin

dbname="aDatabase"
print "Please enter your user name associating with mysql DB: "
uName= gets
print "Please enter your password: "
pwd= gets

m = Mysql.real_connect("localhost",uName,pwd)
m.select_db(dbname)
result = m.query("SELECT * FROM ping_content")

m.close
end

But when I attempt to run it, it returns Access denied as shown below. Anyone got idea on why?

george@linux:~/updating> ruby dbConn.rb
Please enter your user name associating with mysql DB: root
Please enter your password: xxxxxx
dbConn.rb:14:in `real_connect': Access denied for user: 'root (Mysql::Error)
@localhost' (Using password: YES) from dbConn.rb:14

rob
April 21st, 2006, 07:19 PM
This looks like a problem with the MySQL host priv. Put in a % instead of localhost in your user's row in the mysql.user table, and see what happens.

harkerboy
April 22nd, 2006, 05:31 PM
This looks like a problem with the MySQL host priv. Put in a % instead of localhost in your user's row in the mysql.user table, and see what happens.

Hello there,
thanks for your reply. do you mean that I have to change the code to be
m = Mysql.real_connect(%,uName,pwd) instead to see what happened?
well, it shows an error:

george@linux:~/final project/updating> ruby dbConn.rb
dbConn.rb:14: syntax error
m = Mysql.real_connect(%,uName,pwd)
^
sorry but i'm not sure what you were exactly meaning. Could you explain it in a little bit detail please? cheers.