To reset the password
Follow these steps (can be helpful if you really forget your password and you can try it anytime, even if you're not in the situation at the moment):
- Stop mysqlsudo /etc/init.d/mysql stopor for other distro versionssudo /etc/init.d/mysqld stop
- Start MySQL in safe modesudo mysqld_safe --skip-grant-tables &
- Log into MySQL using rootmysql -uroot
- Select the MySQL database to useuse mysql;
- Reset the passwordupdate user set password=PASSWORD("mynewpassword") where User='root';
- Flush the privilegesflush privileges;
- Restart the serverquit
- Stop and start the server againubuntu and debiansudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql startOn CentOS and Fedora and RHELsudo /etc/init.d/mysqld stop ... sudo /etc/init.d/mysqld start
- Login with new passwordmysql -u root -p
- Type new password and enjoy your server again like nothing happened
