1.修改my.ini文件
在如图加上这句话
skip-grant-tables
2.重新启动Mysql/MariaDb
cmd管理员运行重启mysql
net stop mysql
net start mysql
3.登录mysql
cmd输入mysql -u root -p
遇到enter:直接回车进入mysql
4.输入修改命令
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
此时可能出现
The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
此时再输入
flush privileges
之后再修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
效果如图