1

I've lost the root password and trying to reset it. I have sudo access. Reading other pages on this, I'm trying the following method using the skip-grant-tables option:

$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
$ sudo mysqld --skip-grant-tables &
[1] 17849
$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[1]+  Exit 1                  sudo mysqld --skip-grant-tables

I've tried adding the -h 127.0.0.1 option too as I read somewhere else. I don't know where the mysqld.sock ought to be if it's not where it's trying to find it, I'm a little lost where to go next.

I am able to enter the MySQL prompt on another MySQL user/pw but that user doesn't have permission to access the "mysql" database to reset the password.

Any help?

Martyn
  • 6,031
  • 12
  • 55
  • 121

1 Answers1

0

Check this question for the same error

And in order to recover the password, you simply have to follow these steps:

  1. Stop the MySQL server process with the command sudo service mysql stop
  2. Start the MySQL server with the command sudo mysqld_safe --skip-grant-tables --skip-networking &
  3. Connect to the MySQL server as the root user with the command mysql -u root

At this point, you need to issue the following MySQL commands to reset the root password:

mysql> use mysql;
​mysql> update user set authentication_string=password('NEWPASSWORD') where user='root';
​mysql> flush privileges;
​mysql> quit

Where NEWPASSWORD is the new password to be used.

  • Restart the MySQL daemon with the command sudo service mysql restart. You should now be able to log into MySQL with the new password.

And that's it. You can now set, reset, and recover your MySQL password.

Reference

Robert
  • 39,162
  • 17
  • 99
  • 152
amal50
  • 981
  • 2
  • 21
  • 35
  • Your link suggests that the error occurs because mysqld is not running. This ought to be the case yes because we are deliberately stopping it, I don't want to start it, right? I tried your commands anyway but still same error. – Martyn Nov 01 '17 at 13:24