You can try to mysqld
boot in safe mode.
Note, however, mysqld
that booting in safe mode using is a bit more complicated. Here is a basic step:
-
Find
my.cnf
the file :my.cnf
is the MySQL configuration file, usually located in/etc/my.cnf
,/etc/mysql/my.cnf
or~/.my.cnf
. -
Edit
my.cnf
the file :[mysqld]
Add the following line below the section of the file:skip-grant-tables
This will allow MySQL to skip the privilege table the next time it starts, allowing you to log in directly.
-
Restart the MySQL service :
sudo systemctl stop mysqld sudo systemctl start mysqld
-
Connect to MySQL and reset the password :
mysql -u root USE mysql; UPDATE user SET authentication_string=PASSWORD("newpassword") WHERE User='root'; FLUSH PRIVILEGES; EXIT;
Replace
"newpassword"
with your desired new password. -
To restore the original
my.cnf
settings : editmy.cnf
the file, removeskip-grant-tables
the line, and restart the MySQL service again.
Remember, before editing any configuration files, it's a good idea to make a backup in case something goes wrong. .