Mysql 忘记密码 Linux

1.检查服务是否启动

ps -ef | grep -i mysql

2.如果启动了关闭它

service mysqld stop

3.修改mysql的配置文件 my.cnf,一般在/etc目录下,不在就搜索一下

vi /etc/my.cnf

4.在文件的[mysqld]下面添加一行

skip-grant-tables

5.保存,重启mysql

service mysqld start

6.无密码方式登录

[root@localhost src]#  mysql -u root

7.进入mysql

mysql> use mysql;

8.修改密码

mysql>  update user set password=password('123456') where user='root';

9.重置

mysql>  flush privileges;

10.退出去用新的密码试一下,不行就重来一遍

原文地址:https://www.cnblogs.com/leaf-cq/p/15079686.html