How to recover password root in Mysql

To recover password root in MySql

For that we managed many servers and passwords by avoidable which it seems arrive a day that we needed to change or to recover the password of root in mysql, or because it forgets to us, it is lost to us, or because a machine arrives at our hands that formed it another person and it is impossible to contact with him (certainly this sounds to you of something).

Step by step to modify password of root in MySql

root@servidor # mysql - or root - p Enter password: 
ERROR 1045 (28000): For Access denied user €˜root'@'localhost€™ (using password: YES)

We go to the grain, the situation is the following one: We have a demon mysql working of which we do not have nor idea of what password is his, but have physical access to that machine, or access by remote connection SSH, if we are within one of these two cases we will be able to modify password present without knowing the one that at the moment is in operation.

Modifying password of root lost in mysql | to recover password root in mysql
First of all to make a simple explanation, demon in Linux is called to the service that works in background and it never stops safe of form manual, damages or it attacks Hacker DDos Refusal on watch.

Logeate as user root of the machine

oscar@servidor: /$ his root Password:

To stop the basic Service of Mysql Data

root@servidor: /# service mysql stop mysql stop/waiting

To initiate mysql with privileges skip Grant tables
This option causes that the machine servant does not use the system of privileges of mysql.
We add the option €“ skip-networking& to enter mysql without password only from LOCALHOST, in this way we are cautious if one is a servant who is in operation under a Public IP.

root@servidor: /# mysqld_safe --skip-Grant-tables --skip-networking& [1] 3035


He gives back this to me: 40405 11:56: 14 mysqld_safe Logging to syslog.
140405 11:56: 14 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

Now we entered mysql without password
As you see there are problems no to enter until the kitchen without password some.

root@servidor: /# mysql - or root Welcome to the MySQL monitor.  Commands end with; or \ g.
Your MySQL connection you go is 1 Server version: 5.1.69-0ubuntu 0.10.04.1 (Ubuntu)

We modify the password of root

mysql> UPDATE to user SET password=PASSWORD (€˜nuevacontrasea€™) WHERE user='root';

We refresh the permissions of Mysql
If we did not refresh the changes will not be effective.

mysql> flush privileges;

We leave Mysql

mysql> exit

We do restart of the service

root@servidor: /# service mysql restart

With this already we have entered mysql as root without password, we have modified it, and the service is working just as at the outset.

I hope that this article serves to you as help,
A greeting,
Oscar/Whitechsolutions Barcelona