1、在mysql根目录下新建配置文件my.ini,添加下面的代码
[mysqld]
skip-grant-tables
2、上述配置文件添加后重启MySQL,输入mysql -h localhost -u root -p,要求输密码的时候直接回车即可。
3、修改密码:
>use mysql;
5.7以及往后版本的mysql重置密码的语句应该是:
>update user set authentication_string=password('新密码') where user='root';
之前版本的应该是:
SET PASSWORD FOR "root"=PASSWORD("新密码");)
刷新权限,然后退出。
>FLUSH PRIVILEGES;
>quit;