Windows平台
net stop mysqlmysqld --skip-grant-tables #阻塞#换个终端mysql> use mysql;> update user set password = password('xxxx') where user = 'root';> flush privileges;> exit;#关闭mysqld --skip-grant-tables 终端net start mysql
Linux平台
# systemctl stop mysqld修改配置文件添加 --skip-grant-tables # vim /etc/my.cnf 在[mysqld]下面添加 skip-grant-tables# systemctl start mysqld# mysql> use mysql;> update user set password = password('xxxx') where user = 'root';> flush privileges;> exit;# systemctl stop mysqld修改配置文件取消 --skip-grant-tables# systemctl start mysqld
![[MySQL]忘记root密码 - 图1](/uploads/projects/zhangsan-560n7@dqoa6r/084ec9faaec628bcccdc2058938d9cdf.png)