关于MySQL忘记root密码的解决办法
一、利用skip-grant-tables进入MySQL
其中分两种情况:
1、MySQL8.0之前的可以通过在MySQL配置文件中添加skip-grant-tables进行无密码登录
2、MySQL8.0和以后的版本修改配置文件已经不行了,需在管理员命令终端执行:mysqld --console --skip-grant-tables --shared-memory,然后另开一个命令终端进行无密码登录
二、无密码登录后,修改密码为空即可
update mysql.user set authentication_string=’’ where user=‘root’ and host=‘localhost’;
这里也需注意老版本的密码列为password,并且需要用password()函数,而新版本的是authentication_string,且不用password()函数,它会自动加密。