linux mysql忘记root密码

修改本地mysql目录中的my.ini文件

vim /etc/my.cnf

在[mysqld]下新增如下配置

skip-grant-tables

重启mysql服务

service mysqld restart

进入MySQL

mysql -uroot
> use mysql;

修改密码


update user set authentication_string = password("123456") where user = "root";

注意,不同MySQL版本的密码字段名不一样,我装的版本命名是authentication_string,其他版本可能命名是"password"

**删除之前 /etc/my.cnf skip-grant-tables **

一定要记住还原之前的修改,否则有安全隐患

再次重启mysql服务

service mysqld restart

完成!!!

猜你喜欢

转载自blog.csdn.net/weixin_39416711/article/details/84635788