Unable to reset MySQL root password, tried everthing

Well, let's first clarify that I have read all questions from Ask Ubuntu about this issue and I have followed all steps from the official docs:

help.ubuntu.com

dev.mysql.com

I'm using Ubuntu 16.04.1 LTS

So before someone suggests anything that I've probably already tried, I'm going to show what I did:

root@localhost:/# sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.

MySQL stopped correctly.

root@localhost:/# sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
[1] 3316
root@localhost:/#

Here I don't know if this was working or not, so I follow the steps anyway.

root@localhost:/# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@localhost:/#

It seems it does not work, as service is not started. As I can't continue with the next steps I try the other method (purge).

After using:

sudo apt-get --purge remove
sudo apt-get install

I try the next step:

root@localhost:/# mysqladmin -u root password MyNewPassword
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
root@localhost:/#

As this also don't work I've tried other methods mentioned on the mysql web:

So I kill mysql process as pointed there and then I use

root@localhost:/# mysqld_safe --init-file=/home/me/mysql-init &
[1] 5267
root@localhost:/# 2017-02-01T12:47:49.250083Z mysqld_safe Logging to syslog.
2017-02-01T12:47:49.252427Z mysqld_safe Logging to '/var/log/mysql/error.log'.

2017-02-01T12:47:49.254765Z mysqld_safe Logging to '/var/log/mysql/error.log'.

2017-02-01T12:47:49.257045Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

[1]+  Salida 1                mysqld_safe --init-file=/home/me/mysql-init
root@localhost:/#

Now is when I was getting out of options, so I also try another method mentioned here on Ask Ubuntu:

root@localhost:/# sudo dpkg-reconfigure mysql-server-5.7
Checking if update is needed.
This installation of MySQL is already upgraded to 5.7.17, use --force if you still need to run mysql_upgrade
root@localhost:/#

And now I'm really out of options, so any suggestions are welcome.


I had the same problem, and I solved it by executing this line:

$ sudo mkdir /var/run/mysqld; sudo chown mysql /var/run/mysqld

before executing this line:

root@localhost:/# mysqld_safe --init-file=/home/me/mysql-init &

For me, these steps worked better.

I think there is a cleaner way to do this, but for me, it was a quick and efficient workaround.


I couldn't get mysql to reinstall no matter what I tried, I ended up just needing to try and reset the password.

I had to go this route on Ubuntu 16.04.1 LTS. I spent an hour or more trying all other suggestions from MySql website to everything on SO as well as the AskUbuntu Q&A's, I finally got it working with:

Note: while it showed Enter password for user root, I didnt have the original password so I just entered the same password to be used as the new password.

Note: there was no /var/log/mysqld.log only /var/log/mysql/error.log

Also note this did not work for me:
sudo dpkg-reconfigure mysql-server-5.7

Nor did:
sudo dpkg-reconfigure --force mysql-server-5.5

Make MySQL service directory.
sudo mkdir /var/run/mysqld

Give MySQL user permission to write to the service directory.
sudo chown mysql: /var/run/mysqld

Then:

  1. kill the current mysqld pid
  2. run mysqld with sudo /usr/sbin/mysqld &
  3. run /usr/bin/mysql_secure_installation

    Output from mysql_secure_installation

    root@myServer:~# /usr/bin/mysql_secure_installation

    Securing the MySQL server deployment.

    Enter password for user root:

    VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?

    Press y|Y for Yes, any other key for No: no Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

    New password:

    Re-enter new password: By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success.

    Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.

    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success.

    By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

    • Dropping test database... Success.

    • Removing privileges on test database... Success.

    Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success.

    All done!