# Changing default password for root user mysql

**URL:** <https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989>\
**Category:** Ansible Project\
**Created:** [October 16, 2012, 11:19pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989 "2012-10-16T23:19:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [October 16, 2012, 11:19pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/1 "2012-10-16T23:19:39Z")

</div>

Hi.

I’m trying to change the password of the root user for a fresh mysql install with :

- name: Changing default pass for user root for mysql  
action: mysql\_user name=root password=root

but ir doesn’t work.

am I missing something here ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 16, 2012, 11:23pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/2 "2012-10-16T23:23:30Z")

</div>

I believe that's only there for database users. Those using MySQL  
may know. I don't use it.

---

<div class="post-metadata">

**Author:** ![Giuliano\_Barberi](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@Giuliano\_Barberi](https://forum.ansible.com/u/Giuliano_Barberi)\
**Post date:** [October 17, 2012, 2:32pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/3 "2012-10-17T14:32:54Z")

</div>

Users in MySQL are also attached to specific hosts. I’m not sure what the behavior is when you don’t specify a host in the MySQL Ansible module. You can see how these guys do it in their LAMP setup here:  
[https://github.com/fourkitchens/server-playbooks/blob/master/common-tasks/mysql-secure.yml](https://github.com/fourkitchens/server-playbooks/blob/master/common-tasks/mysql-secure.yml)

Regards

---

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [October 17, 2012, 5:30pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/4 "2012-10-17T17:30:39Z")

</div>

if you do not specify the host is supposed to connect to localhost and that if what I want.

my playbook is running in pull mode.

---

<div class="post-metadata">

**Author:** ![Mark\_Theunissen](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@Mark\_Theunissen](https://forum.ansible.com/u/Mark_Theunissen)\
**Post date:** [October 18, 2012, 8:48pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/5 "2012-10-18T20:48:56Z")

</div>

What errors do you get? What is the result?

MySQL users are identified through a combination of user and host. In a fresh MySQL install, there will be several entries for the root user.

This Ansible playbook secures the MySQL server:

[https://github.com/fourkitchens/server-playbooks/blob/master/common-tasks/mysql-secure.yml](https://github.com/fourkitchens/server-playbooks/blob/master/common-tasks/mysql-secure.yml)

---

<div class="post-metadata">

**Author:** ![Giuliano\_Barberi](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@Giuliano\_Barberi](https://forum.ansible.com/u/Giuliano_Barberi)\
**Post date:** [October 19, 2012, 5:26pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/6 "2012-10-19T17:26:42Z")

</div>

No, the host param in mysql\_user command is the host to associate w/ that user login, not the host where you are connecting to.

[http://ansible.cc/docs/modules.html#mysql-user](http://ansible.cc/docs/modules.html#mysql-user)

---

<div class="post-metadata">

**Author:** ![PePe\_Amengual](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PePe\_Amengual](https://forum.ansible.com/u/PePe_Amengual)\
**Post date:** [October 19, 2012, 8:08pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/7 "2012-10-19T20:08:57Z")

</div>

ohh I seem so is the part ‘user’@‘THISISTHEHOST’ part.

I solved the problem using mysqladmin now I know that is not possible with the mysql\_user module.

---

<div class="post-metadata">

**Author:** ![Mark\_Theunissen](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@Mark\_Theunissen](https://forum.ansible.com/u/Mark_Theunissen)\
**Post date:** [October 25, 2012, 7:26pm UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/8 "2012-10-25T19:26:37Z")

</div>

It should be possible - there are two host parameters, the one associated with the user, and one that should be connected to:

[http://ansible.cc/docs/modules.html#mysql-user](http://ansible.cc/docs/modules.html#mysql-user)

---

<div class="post-metadata">

**Author:** ![Ravikumar\_Wagh](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@Ravikumar\_Wagh](https://forum.ansible.com/u/Ravikumar_Wagh)\
**Post date:** [June 4, 2018, 7:54am UTC](https://forum.ansible.com/t/changing-default-password-for-root-user-mysql/11989/9 "2018-06-04T07:54:56Z")

</div>

Hi,

This will solve your problem.

- name: Update mysql root password  
mysql\_user: name=root host={{ item }} login\_user=root login\_password={{ mysql\_default\_pass }} password={{ mysql\_new\_root\_password }}  
with\_items:
- 127.0.0.1
- localhost

You can fine mysql default password in my.cnf or mysql log file.
