# RE: Access denied error using mysql & database cookbooks

**URL:** <https://discourse.chef.io/t/re-access-denied-error-using-mysql-database-cookbooks/6974>\
**Category:** Chef Infra (archive)\
**Created:** [September 14, 2015, 1:01am UTC](https://discourse.chef.io/t/re-access-denied-error-using-mysql-database-cookbooks/6974 "2015-09-14T01:01:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkeane](https://avatars.discourse-cdn.com/v4/letter/k/9fc29f/32.png) [@kkeane](https://discourse.chef.io/u/kkeane)\
**Post date:** [September 14, 2015, 1:01am UTC](https://discourse.chef.io/t/re-access-denied-error-using-mysql-database-cookbooks/6974/1 "2015-09-14T01:01:51Z")

</div>

Did you try connecting with 127.0.0.1 instead of through the socket?

The mysql cookbook installs a new instance of mysql that is not available through the standard socket. I notice that you specified what _should_ be the correct socket, but who knows?

I also saw your later note on the problem related to /var/lib/mysql - maybe the there is a standard mysql instance lurking somewhere that accesses this directory, and the two instances are interfering with each other?

Kevin Keane

The NetTech

[http://www.4nettech.com](http://www.4nettech.com)

Our values: Privacy, Liberty, Justice

See [https://www.4nettech.com/corp/the-nettech-values.html](https://www.4nettech.com/corp/the-nettech-values.html)

-----Original message-----  
From: Greg Barker [fletch@fletchowns.net](mailto:fletch@fletchowns.net)  
Sent: Sunday 13th September 2015 4:30  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Access denied error using mysql & database cookbooks

Can’t seem to figure out what is causing this error. I’ve been using this same cookbook for awhile and it seemed like it stopped working recently. I tried updating to the latest versions of the cookbooks and still encounter the issue.

Here’s my recipe:

mysql2\_chef\_gem “default” do  
action :install  
end

mysql\_service “default” do  
port "3306"  
version "5.5"  
initial\_root\_password "changeme"  
action [:create, :start]  
data\_dir "/var/lib/mysql"  
end

mysql\_connection\_info = {  
:socket =\> “/run/mysql-default/mysqld.sock”,  
:username =\> “root”,  
:password =\> “changeme”  
}

mysql\_database “test\_db” do  
connection mysql\_connection\_info  
action :create  
end

This results in the following error:

[2015-09-13T11:23:01+00:00] ERROR: mysql\_database[test\_db] (fletchowns::mysql line 19) had an error: Mysql2::Error: Access denied for user ‘root’@‘localhost’ (using password: YES)

Here’s the output from the run: [https://gist.github.com/fletchowns/66c13db76d20be182597](https://gist.github.com/fletchowns/66c13db76d20be182597)

Base box is opscode\_debian-7.8\_chef-provisionerless.box

I tried to ssh into the machine but couldn’t seem to connect to mysql there either:

$ vagrant ssh  
Linux packer-debian-7 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u1 x86\_64

The programs included with the Debian GNU/Linux system are free software;  
the exact distribution terms for each program are described in the  
individual files in /usr/share/doc/\*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent  
permitted by applicable law.  
You have mail.  
Last login: Sun Sep 13 11:13:20 2015 from 10.0.2.2  
vagrant@default-debian-78:~ ps aux | grep mysql root 17062 0.0 0.0 4184 728 ? S 11:14 0:00 /bin/sh /usr/bin/mysqld\_safe --defaults-file=/etc/mysql-default/my.cnf mysql 17236 0.1 1.9 330460 39956 ? Sl 11:14 0:00 /usr/sbin/mysqld --defaults-file=/etc/mysql-default/my.cnf --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql-default/error.log --pid-file=/run/mysql-default/mysqld.pid --socket=/run/mysql-default/mysqld.sock --port=3306 vagrant 17364 0.0 0.0 7836 876 pts/0 S+ 11:16 0:00 grep mysql vagrant@default-debian-78:~ ls -la /run/mysql-default/mysqld.sock  
srwxrwxrwx 1 mysql mysql 0 Sep 13 11:14 /run/mysql-default/mysqld.sock  
vagrant@default-debian-78:~$ sudo su -  
root@default-debian-78:~# mysql -u root -S /run/mysql-default/mysqld.sock -p  
Enter password:  
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)  
root@default-debian-78:~#

Any help is greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![fletchowns](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/fletchowns/32/53_2.png) [@fletchowns](https://discourse.chef.io/u/fletchowns)\
**Post date:** [September 14, 2015, 5:50am UTC](https://discourse.chef.io/t/re-access-denied-error-using-mysql-database-cookbooks/6974/2 "2015-09-14T05:50:26Z")

</div>

Yup I originally had it as 127.0.0.1 and it didn't work with that either, I  
switched it to the socket thinking that might resolve the issue.

I'll try bringing up the base box without installing anything and see if  
it's already got something in /var/lib/mysql.

On Sun, Sep 13, 2015 at 6:01 PM, Kevin Keane Subscription \<  
[subscription@kkeane.com](mailto:subscription@kkeane.com)\> wrote:

> Did you try connecting with 127.0.0.1 instead of through the socket?
> 
> The mysql cookbook installs a new instance of mysql that is not available  
> through the standard socket. I notice that you specified what _should_ be  
> the correct socket, but who knows?
> 
> I also saw your later note on the problem related to /var/lib/mysql -  
> maybe the there is a standard mysql instance lurking somewhere that  
> accesses this directory, and the two instances are interfering with each  
> other?
> 
> Kevin Keane
> 
> The NetTech
> 
> [http://www.4nettech.com](http://www.4nettech.com)
> 
> Our values: Privacy, Liberty, Justice
> 
> See [https://www.4nettech.com/corp/the-nettech-values.html](https://www.4nettech.com/corp/the-nettech-values.html)
> 
> -----Original message-----  
> _From:_ Greg Barker [fletch@fletchowns.net](mailto:fletch@fletchowns.net)  
> _Sent:_ Sunday 13th September 2015 4:30  
> _To:_ [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
> _Subject:_ [chef] Access denied error using mysql & database cookbooks
> 
> Can't seem to figure out what is causing this error. I've been using this  
> same cookbook for awhile and it seemed like it stopped working recently. I  
> tried updating to the latest versions of the cookbooks and still encounter  
> the issue.
> 
> Here's my recipe:
> 
> mysql2\_chef\_gem "default" do  
> action :install  
> end
> 
> mysql\_service "default" do  
> port "3306"  
> version "5.5"  
> initial\_root\_password "changeme"  
> action [:create, :start]  
> data\_dir "/var/lib/mysql"  
> end
> 
> mysql\_connection\_info = {  
> :socket =\> "/run/mysql-default/mysqld.sock",  
> :username =\> "root",  
> :password =\> "changeme"  
> }
> 
> mysql\_database "test\_db" do  
> connection mysql\_connection\_info  
> action :create  
> end
> 
> This results in the following error:
> 
> [2015-09-13T11:23:01+00:00] ERROR: mysql\_database[test\_db]  
> (fletchowns::mysql line 19) had an error: Mysql2::Error: Access denied for  
> user 'root'@'localhost' (using password: YES)
> 
> Here's the output from the run:  
> [chef mysql access denied · GitHub](https://gist.github.com/fletchowns/66c13db76d20be182597)
> 
> Base box is opscode\_debian-7.8\_chef-provisionerless.box
> 
> I tried to ssh into the machine but couldn't seem to connect to mysql  
> there either:
> 
> $ vagrant ssh  
> Linux packer-debian-7 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u1 x86\_64
> 
> The programs included with the Debian GNU/Linux system are free software;  
> the exact distribution terms for each program are described in the  
> individual files in /usr/share/doc/\*/copyright.
> 
> Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent  
> permitted by applicable law.  
> You have mail.  
> Last login: Sun Sep 13 11:13:20 2015 from 10.0.2.2  
> vagrant@default-debian-78:~$ ps aux | grep mysql  
> root 17062 0.0 0.0 4184 728 ? S 11:14 0:00 /bin/sh  
> /usr/bin/mysqld\_safe --defaults-file=/etc/mysql-default/my.cnf  
> mysql 17236 0.1 1.9 330460 39956 ? Sl 11:14 0:00  
> /usr/sbin/mysqld --defaults-file=/etc/mysql-default/my.cnf --basedir=/usr  
> --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql  
> --log-error=/var/log/mysql-default/error.log  
> --pid-file=/run/mysql-default/mysqld.pid  
> --socket=/run/mysql-default/mysqld.sock --port=3306  
> vagrant 17364 0.0 0.0 7836 876 pts/0 S+ 11:16 0:00 grep mysql  
> vagrant@default-debian-78:~$ ls -la /run/mysql-default/mysqld.sock  
> srwxrwxrwx 1 mysql mysql 0 Sep 13 11:14 /run/mysql-default/mysqld.sock  
> vagrant@default-debian-78:~$ sudo su -  
> root@default-debian-78:~# mysql -u root -S /run/mysql-default/mysqld.sock  
> -p  
> Enter password:  
> ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using  
> password: YES)  
> root@default-debian-78:~#
> 
> Any help is greatly appreciated. Thanks!
