How to reset my sql root password ?

Hello everyone,

I forgot the root password to mysql server , is there any to reset it ?

Thank you

Should be able to do the following.

# stop the mysql service
> systemctl stop mysql
# launch the service without grant-tables and networking (to the background)
> /usr/sbin/mysqld --skip-grant-tables --skip-networking &
# login to mysql as root
> mysql -u root
# flush privileges
mysql> FLUSH PRIVILEGES;
# set the root password
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('itbible');
# exit back to bash
mysql> quit
# kill the running session that you launched to the background
> kill %1
# start normally again
> systemctl start mysql

obviously you should change the password to something other than ‘itbible’ :stuck_out_tongue:

That almost worked but I tried doing this and it did the trick:

sudo /usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

Thanks,
Source: https://askubuntu.com/questions/1240542/how-can-i-reset-mysql-server-8-0-root-password-on-ubuntu-20-04/1295497#1295497
Cheers!