Scaffold Uses Wrong Host for MySQL user

I’m following the example Depot app in Agile Web D. with Rails.

The scaffold fails because it is not using the correct host for the
user. Here is the error that the scaffold emits:

Access denied for user ‘jimmy’@’%’ to database ‘depot_development’

The MySql user ‘jimmy’ was created with the host of ‘localhost’, and the
database.yml file is using ‘localhost’ as the host for user ‘jimmy’ on
the depot_development database.

I’m using MySql 5.0.19-nt and Rails 1.1.2.

Can you post your database.yml?

Paul B. wrote:

Can you post your database.yml?
Here is the complete database.yml file contents. Thanks!

##########

MySQL (default setup). Versions 4.1 and 5.0 are recommended.

Install the MySQL driver:

gem install mysql

On MacOS X:

gem install mysql – --include=/usr/local/lib

On Windows:

There is no gem for Windows. Install mysql.so from RubyForApache.

http://rubyforge.org/projects/rubyforapache

And be sure to use new-style password hashing:

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:
adapter: mysql
database: depot_development
username: jimmy
password: letmein
host: localhost

Warning: The database defined as ‘test’ will be erased and

re-generated from your development database when you run ‘rake’.

Do not set this db to the same as development or production.

test:
adapter: mysql
database: depot_test
username: jimmy
password: letmein
host: localhost

production:
adapter: mysql
database: depot_production
username: prod
password: l3tm31n
host: localhost

##########

Paul B. wrote:

That looks pretty standard. I just tried it and it seems to work fine,
did
you do something different than this?

pbarry@paul-barrys-mac-mini:~/projects $ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.18-standard

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> create database depot_development;
Query OK, 1 row affected (0.03 sec)

mysql> grant all privileges on depot_development.* to
‘jimmy’@‘localhost’
-> identified by ‘letmein’;
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye
pbarry@paul-barrys-mac-mini:~/projects $ rails depot
create
create app/controllers
create app/helpers

pbarry@paul-barrys-mac-mini:~/projects $ cd depot
pbarry@paul-barrys-mac-mini:~/projects/depot $ cat config/database.yml |
ruby -e ‘$stdin.each {|line| puts line.sub(/username: root/,“username:
jimmy”).sub(/password:/,“password: letmein”) }’ > config/database.yml
pbarry@paul-barrys-mac-mini:~/projects/depot $ rake db:migrate
(in /Users/pbarry/projects/depot)
pbarry@paul-barrys-mac-mini:~/projects/depot $

What happens when you run this from the command line?

mysql -D depot_development -u jimmy -pletmein

Do you get in?

Thanks!
When I log in at the command line I get an access denied error, however
I can log in fine with a GUI tool using the same credentials…strange.

When I granted privileges I did not use the IDENTIFIED BY parameter.
This is what was causing my problems. The MySql example did not inlcude
this parameter in their sample.

Once I re-issued the grant all privileges using your syntax…I was able
to log in at the command and create the scaffold just fine.

Thanks for your help!

That looks pretty standard. I just tried it and it seems to work fine,
did
you do something different than this?

pbarry@paul-barrys-mac-mini:~/projects $ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 4.1.18-standard

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> create database depot_development;
Query OK, 1 row affected (0.03 sec)

mysql> grant all privileges on depot_development.* to
‘jimmy’@‘localhost’
-> identified by ‘letmein’;
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye
pbarry@paul-barrys-mac-mini:~/projects $ rails depot
create
create app/controllers
create app/helpers

pbarry@paul-barrys-mac-mini:~/projects $ cd depot
pbarry@paul-barrys-mac-mini:~/projects/depot $ cat config/database.yml |
ruby -e ‘$stdin.each {|line| puts line.sub(/username: root/,“username:
jimmy”).sub(/password:/,“password: letmein”) }’ > config/database.yml
pbarry@paul-barrys-mac-mini:~/projects/depot $ rake db:migrate
(in /Users/pbarry/projects/depot)
pbarry@paul-barrys-mac-mini:~/projects/depot $

What happens when you run this from the command line?

mysql -D depot_development -u jimmy -pletmein

Do you get in?