Ruby connection to MySQL

software development

#1

I am having difficulty connecting to my database from a Ruby script. I receive an “access denied” message from mysql whenever I try to run the script. I am able to access the database from PHP using the same server name, user and password, although those scripts are being run from the web rather than the command line.

The script is being run from a telnet session.

The user name is configured to allow access from a host of “%.dreamhost.com”. I also tried adding a host of “%”, but that does not make a difference.

The script is (2 lines):
require 'mysql’
my= Mysql.real_connect(‘mysql.mydomain.org’,‘myuser’,‘mypass’, ‘mydatabasename’)

The message I get upon running the script is:
test.rb:2:in `real_connect’: Access denied for user ‘myuser’@‘snapple.dreamhost.com’ (using password: YES) (Mysql::Error)
from test.rb:2

Sometimes an IP address is shown rather than ‘snapple.dreamhost.com’.


#2

it seems you did not set up your database in the server properlly. the error message indicates that you can’t connec to the server with the username and password.

first, go to DH panel --> Goodies --> Manage MySQL to check whether your database is there.

second, check the user name and password. note that the name and password are those you created in DH panel.

if everything is correct, try to create a new database in a new database server and try to connect to the new database. some thing could go wrong when you set up your previous database.

good luck

Save [color=#CC0000]$97[/color] (max discount) on dreamhost by using promo code: [color=#CC0000]97CRAZY[/color].


#3

How many times did I overlook the database name? My database names are prefixed with my account name for uniqueness, but I left out the prefix in my script. The name looked right because it’s the name I use everywhere else. Doh!


#4

correct me if i’m wrong. If you are connectingn from the telnet locally, you should configure to allow access from your local machine (your IP address) under the same user name.

Save [color=#CC0000]$97[/color] (max discount) on dreamhost by using promo code: [color=#CC0000]97CRAZY[/color].