# Scaffold Uses Wrong Host for MySQL user

**URL:** <https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819>\
**Category:** Rails\
**Created:** [May 7, 2006, 1:24am UTC](https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819 "2006-05-07T01:24:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@jimmy](https://www.ruby-forum.com/u/jimmy)\
**Post date:** [May 7, 2006, 1:24am UTC](https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819/1 "2006-05-07T01:24:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@jimmy](https://www.ruby-forum.com/u/jimmy)\
**Post date:** [May 7, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819/2 "2006-05-07T15:16:17Z")

</div>

Can you post your database.yml?

---

<div class="post-metadata">

**Author:** ![jimmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@jimmy](https://www.ruby-forum.com/u/jimmy)\
**Post date:** [May 7, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819/3 "2006-05-07T17:40:27Z")

</div>

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](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](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

##########

---

<div class="post-metadata">

**Author:** ![jimmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@jimmy](https://www.ruby-forum.com/u/jimmy)\
**Post date:** [May 7, 2006, 7:42pm UTC](https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819/4 "2006-05-07T19:42:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jimmy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee59a6/32.png) [@jimmy](https://www.ruby-forum.com/u/jimmy)\
**Post date:** [May 7, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/scaffold-uses-wrong-host-for-mysql-user/59819/5 "2006-05-07T18:46:10Z")

</div>

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?
