Sunday, March 14, 2010

MySQL root password reset

This is rather annoying, so here is the complete procedure:

Get MySQL to be in the safe mode:
#---
service mysqld stop
mysqld_safe --skip-grant-tables &
#---


Start the MySQL shell:
#---
mysql -u root
#---


At the MySQL shell (this is NOT safe):
USE mysql;
UPDATE user SET PASSWORD=PASSWORD("<plain text root password for mysql>") WHERE User='root';
FLUSH PRIVILEGES;
FLUSH TABLES;
\q


Back at the root shell:
#---
kill `cat /var/run/mysqld/mysqld.pid`
service mysqld start
#---


NOTE: MySQL records its shell commands at ~/.mysql_history This means that
your passwords (informed as I shown you) are recorded in plain text at this
file. It is advised to remove this file after applying the commands above
displayed:
#---
rm -f ~/.msyql_history
#---

No comments: