Wednesday, December 19, 2007

I lost that damn mysql password again

With my memory not being what it once was I tend to forget things like database passwords on boxes that I don't need to constantly maintain.

Here is the process of retrieving a lost mysql root password:

  • Stop the MySQL server process.
# /etc/init.d/mysql stop
  • Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password
# mysqld_safe --skip-grant-tables &
  • Connect to mysql server as the root user
# mysql -u root
  • Setup new root password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
  • Exit and restart MySQL server
# killall mysqld
# /etc/init.d/mysql start

No comments: