# Access Denied for user

**URL:** <https://www.ruby-forum.com/t/access-denied-for-user/119694>\
**Category:** Rails\
**Created:** [November 9, 2007, 9:52am UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694 "2007-11-09T09:52:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [November 9, 2007, 9:52am UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694/1 "2007-11-09T09:52:37Z")

</div>

I’m getting ‘Access denied for user … Using password:YES …  
Mysql::Error’ message. The OS is Solaris 5.9, Ruby is 1.8.6 and Rails  
is 1.2.3. AFAIK these are all fairly new adn shouldn’t suffer from the  
‘old password’ effect - even so , I have forced the password to be ‘old  
style’ to be on the safe side. The database.yml looks OK to me

development:  
adapter: mysql  
database: mydatabase1\_development  
username: tobyr  
password: mypassword  
#socket: /tmp/mysql.sock  
host: localhost  
port: 3406

(I’ve tried with ‘socket’ instead of port, with the same result)

I know the username and password are right because I can use them to get  
into mysql from the CLI.

Any ideas?

thanks!

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [November 9, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694/2 "2007-11-09T13:35:35Z")

</div>

Is this because of the permission set up on the mysql?  
i.e. certain users or groups have certain permissions from certain  
machines, ip-addresses.

On Nov 9, 8:52 am, Toby R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [November 9, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694/3 "2007-11-09T14:34:33Z")

</div>

Thanks for the reply -  
What identify does Ruby use when accessing mysql? For example, from the  
command line I can run

~toby/rails/mydatabase#mysql -u tobyr -p  
Password:

but if I run (from the same command line prompt)  
~toby/rails/mydatabase#ruby my-test-script.sh

removed\_email\_address@domain.invalid wrote:

> Is this because of the permission set up on the mysql?  
> i.e. certain users or groups have certain permissions from certain  
> machines, ip-addresses.
> 
> On Nov 9, 8:52 am, Toby R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [November 9, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694/4 "2007-11-09T16:46:04Z")

</div>

The standard mysql port is 3306, not 3406. Do you have mysql running on  
a different port? If not, change database.yml to

development:  
adapter: mysql  
database: mydatabase1\_development  
username: tobyr  
password: mypassword  
#socket: /tmp/mysql.sock  
host: localhost  
port: 3306 # \<- port 3306

-Bill

Toby R. wrote:

> password: mypassword
> 
> thanks!

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [November 9, 2007, 5:14pm UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694/5 "2007-11-09T17:14:24Z")

</div>

Sorry, I should have made that clearer - there are two instances of  
mysql running and the one I want is on 3406. In fact, is there any  
possibility this line is being ignored and port 3306 _is_ being used,  
because if I change ‘port’ to some random number (1234) I get the _same_  
error message (‘Access denied’)? I’m confident I’m editing the right  
section of datanbase.yml because if I change, say, the username then I  
see the new username reflected in the error message I get.

William P. wrote:

> The standard mysql port is 3306, not 3406. Do you have mysql running on  
> a different port? If not, change database.yml to
> 
> development:  
> adapter: mysql  
> database: mydatabase1\_development  
> username: tobyr  
> password: mypassword  
> #socket: /tmp/mysql.sock  
> host: localhost  
> port: 3306 # \<- port 3306
> 
> -Bill
> 
> Toby R. wrote:
> 
> > password: mypassword
> > 
> > thanks!
> 
> –  
> Sincerely,
> 
> William P.

---

<div class="post-metadata">

**Author:** ![tobyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ebca7d/32.png) [@tobyr](https://www.ruby-forum.com/u/tobyr)\
**Post date:** [November 11, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/access-denied-for-user/119694/6 "2007-11-11T21:09:47Z")

</div>

Fixed it! The problem was related to the two instances of Mysql. I  
wanted to connect to the instance on the non-standard port (3406). I  
correctly added the ‘port: 3406’ line to database.yml, but I left ‘host:  
localhost’. However, as implied at  
[http://www.kitebird.com/articles/ruby-mysql.html#TOC\_12](http://www.kitebird.com/articles/ruby-mysql.html#TOC_12) ‘localhost’ is  
relevant to the Unix socket, not a TCP/IP connection. So, strange as it  
may seem, replacing ‘localhost’ with the Fully Qualified Domain Name  
fixed the problem.
