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