Reset MySQL root password
Answer:
If you have forgotten the MySQL root password, follow the steps below to reset the root password (for Ubuntu/Debian).
1. Shutdown MySQL
# /etc/init.d/mysql stop
2. Startup MySQL using command without grant tables, take the process to run in background
# /usr/bin/mysqld_safe --skip-grant-tables &
3. Login into the MySQL database
# mysql --user=root mysql
4. Reset password
mysql>update user set Password=PASSWORD('newpassword') WHERE User='root';
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql>flush privileges;
Query OK, 0 rows affected (0.02 sec)
5. Shutdown MySQL
Bring the MySQL server process to foreground now and kill it by Ctrl-C
# fg
[Ctrl-C]
6. Start MySQL using normal way
# /etc/init.d/mysql start
That's all.