首先停止MySQL服务,可以从服务中停止Mysql这个服务(有的系统是MySQL80或者MySQL57),也可以使用命令行输入“net stop mysql”结束该服务;
打开命令行,输入“mysqld --console --skip-grant-tables --shared-memory”语句,执行,这时命令行会卡住,不要着急,打开一个新的命令行,输入“mysql -u root”便可以无密码直接进入MySQL了;
修改密码
update mysql.user set authentication_string=password(‘123456’) where user=‘root’ and Host = ‘localhost’;
注意,如果在第三步中遇到“ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement”问题,只需要执行以下语句“flush privileges”之后再执行修改密码语句便可以成功修改密码了!