第一種
1.1停止mysql服務
1.2以管理員身份運行cmd,執行以下命令
cd C:\Program Files\mysql-5.7.17-winx64\bin mysqld --skip-grant-tables
或者
mysqld_safe
--skip-grant-tables
1.3在不關閉cmd情況下重新以管理員身份運行一個cmd,執行如下命令
cd C:\Program Files\mysql-5.7.17-winx64\bin
mysql -uroot -p
alter user 'root'@'localhost' identified by '123456'; flush privileges;
注:123456是設置root的新密碼,C:\Program Files\mysql-5.7.17-winx64\bin是mysql的地址
第二種
2.1MySQL配置文件my.ini中,在[mysqld]下添加skip-grant-tables
2.2重啟MySQL服務
2.3用管理員身份進入cmd,輸入如下命令
cd C:\Program Files\mysql-5.7.17-winx64\bin;
flush privileges;
alter user 'root'@'localhost' identified by '123456';
注:123456是設置root的新密碼