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 mysql
sudo /etc/init.d/mysql stop
or for other distro versions
sudo /etc/init.d/mysqld stop
Start MySQL in safe mode
sudo mysqld_safe --skip-grant-tables &
Log into MySQL using root
mysql -uroot
Select the MySQL database to use
use mysql;
Reset the password
update user set password=PASSWORD("mynewpassword") where User='root';
Flush the privileges
flush privileges;
Restart the server
quit
Stop and start the server again
ubuntu and debian
sudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql start
On CentOS and Fedora and RHEL
sudo /etc/init.d/mysqld stop ... sudo /etc/init.d/mysqld start
Login with new password
mysql -u root -p
Type new password and enjoy your server again like nothing happened
No comments:
Post a Comment