Update: Fix forgotten MariaDB password on Ubuntu 18.04 and newer.
Update: This method does not work on Ubuntu 16.04, and I have not tested it with newer versions either.
Forgot MySQL server root password? It’s trivial to change it in Ubuntu and Debian.
$ sudo dpkg-reconfigure mysql-server-5.1
To get the version of your package, just type ‘sudo dpkg-reconfigure mysql-server-5″ and press tab a couple of times.
It simply asks for new MySQL root password. Accept the default answer to any other question by pressing enter.
Choosing Password
Select a good password. It must be different from any password already used in your system, because MySQL has it’s own user system, separate from Linux users. For example, MySQL “root” is completely unrelated to the user that can install software in Linux.
Log in with Your New Password
Now you can log in with PhpMyAdmin (http://localhost/phpmyadmin) or command line client
$ mysql -u root -p
Solved Errors
By changing the password, you solve these common errors: “#1045 Cannot log in to the MySQL server”, “ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)”.
Administrivia
Tested succesfully in Ubuntu 10.04 LTS lucid, 11.10 and Ubuntu 12.04 alpha1.
Update: Verified (again) on Ubuntu 10.04 LTS lucid (mysql-server-5.1 5.1.41-3ubuntu12.6, apt 0.7.25.3ubuntu7, dpkg 1.15.5.6ubuntu4) that my databases are intact after this, only root password changes.
Briefly in Finnish: Unohtunut MySQL-palvelimen salasana on helppo vaihtaa.
Nice Article !
I have also worked around this and found that one more step is require in some condition. Kill to old mysqld process.
I have also preapred my own step, please visit my blog:
http://www.dbrnd.com/2015/08/reset-mysql-root-password-ubuntu/
I would not recommend killing daemon processes with SIGKILL and manipulating the user database directly with SQL, if it can be avoided.