02 June 2024

Have forgotten root password of mysql server

$ sudo service mysql stop

$ sudo vi /etc/mysql/mysql.conf.d/reset-mysql-password.cnf

[mysqld] 
skip-grant-tables

$ sudo mysqld_safe --skip-grant-tables &

$ mysql -u root

mysql > UPDATE mysql.user SET authentication_string=null WHERE User='root'; 

mysql > FLUSH PRIVILEGES;

mysql > exit

$ mysql -u root

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';

mysql > FLUSH PRIVILEGES;

sudo rm /etc/mysql/mysql.conf.d/reset-mysql-password.cnf

$ mysql -u root

mysql > 

No comments:

Post a Comment