Saturday, January 10, 2009

How to recover root password in MySQL?


  1. As Linux system root user stop the database process: /etc/init.d/mysql stop
    (or: service mysql stop)

  2. Start MySQL in safe mode and skip the use of the "grant tables": /usr/bin/mysqld_safe --user=mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --datadir=/var/lib/mysql --skip-grant-tables --skip-networking &

  3. Reset the MySQL root password: mysqladmin -u root flush-privileges password newpassword

  4. Stop MySQL running in safe mode: kill `cat /var/run/mysqld/mysqld.pid`

  5. Start MySQL: /etc/init.d/mysql start

  6. The new MySQL root password can now be used: mysql -u root -p
    Respond withthe password: newpassword

1 comment: