How to reset your MySQL root password

By admin, 21 Junho, 2024

If you forgot your MySQL root password, follow these steps to reset it:

1) 1. Stop MySQL Service

sudo systemctl stop mysql

2) 2. Start MySQL in Safe Mode

sudo mysqld_safe --skip-grant-tables &

3) 3. Log into MySQL

mysql -u root

4) 4. Reset Root Password

For MySQL 5.7+:

FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

For MySQL 5.6 and MariaDB:

FLUSH PRIVILEGES; SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');

5) 5. Stop MySQL Safe Mode and Restart

sudo systemctl stop mysql sudo systemctl start mysql

6) 6. Verify New Password

mysql -u root -p

By following these steps, you should be able to reset your MySQL root password successfully.

Back to top

Comentários