# mysql\_user does not find /root/.my.cnf

**URL:** <https://forum.ansible.com/t/mysql-user-does-not-find-root-my-cnf/33829>\
**Category:** Ansible Project\
**Created:** [September 16, 2020, 2:31pm UTC](https://forum.ansible.com/t/mysql-user-does-not-find-root-my-cnf/33829 "2020-09-16T14:31:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@Ed\_Greenberg](https://forum.ansible.com/u/Ed_Greenberg)\
**Post date:** [September 16, 2020, 2:31pm UTC](https://forum.ansible.com/t/mysql-user-does-not-find-root-my-cnf/33829/1 "2020-09-16T14:31:18Z")

</div>

My ansible 2.9.10-1.el7 connects to the target machines as root.

On my target machines, I have /root/.my.cnf with a root password defined under the section [mysql].

Here is the playbook and response

- hosts: databaseservers  
tasks:

- name: add user to mysql  
mysql\_user:  
name: “{{ name }}”  
host: “{{ item }}”  
password: “{{ password }}”  
encrypted: no  
priv: ‘_._:ALL’  
login\_unix\_socket: /var/lib/mysql/mysql.sock  
state: present

with\_items:

- localhost
- 127.0.0.1
- ::1

and I get…

failed: [[awsbeta.happysoftware.com](http://awsbeta.happysoftware.com)] (item=localhost) =\> {“ansible\_loop\_var”: “item”, “changed”: false, “item”: “localhost”, “msg”: “unable to connect to database, check login\_user and login\_password are correct or /root/.my.cnf has the credentials. Exception message: (1045, u"Access denied for user ‘root’@‘localhost’ (using password: NO)")”}

Note that using password is NO.

Most of the posts here concern setting the root password. One fellow, from 2016, questioned on what path the .my.cnf needed to be. Since I log in as root, I figure it’s /root/.my.cnf.

My /root/.my.cnf is:

[mysql]  
user=root  
password=xxxxxxxxxxx  
[mysqldump]  
user=databasebackup  
password=xxxxxxxxxxx

Do I need another section, perhaps? What else might be wrong?

Thanks,  
Ed Greenberg

---

<div class="post-metadata">

**Author:** ![Raju\_Das](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@Raju\_Das](https://forum.ansible.com/u/Raju_Das)\
**Post date:** [September 16, 2020, 4:37pm UTC](https://forum.ansible.com/t/mysql-user-does-not-find-root-my-cnf/33829/2 "2020-09-16T16:37:35Z")

</div>

With Regards  
Raju Das
