1. 停止服务器的运行

  1. sudo systemctl stop mysqld
  2. ps aux | grep mysqld |grep -v grep

image.png

2. 使用—skip-grant-tables选项启动服务器

sudo -u mysql /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid --user=mysql --skip-grant-tables

image.png

3. 不使用密码连接到mysql,执行flush privileges重新加载授权,并更改用户以修改密码

mysql -u root
flush privileges;
alter user 'root'@'localhost' identified by 'Newpassword123,./';

image.png

4. 用新密码登陆mysql

image.png

5. 重启mysql服务器

ps aux | grep mysqld | grep -v grep

image.png

sudo kill -9 19619
ps aux | grep mysqld | grep -v grep

image.png
重启mysql

sudo systemctl start mysqld
ps aux | grep mysqld | grep -v grep

image.png