linux mysql忘记密码

1、查看mysql是否开启

ps -ef | grep -i mysql

在这里插入图片描述
2、如果mysql正在运行,那么先停止mysql

systemctl stop mysqld

3、修改mysql的配置文件my.cnf,一般放在/etc
修改文件 vim /etc/my.cnf 添加 skip-grant-tables

 skip-grant-tables # 跳过数据库权限验证 保存退出。

linux mysql忘记密码_第1张图片
4、重启mysql

systemctl start mysqld

5、进入mysql
在这里插入图片描述
6、修改数据库密码命令

update mysql.user set authentication_string=password('你的密码') where user='root';
//修改语句就是authentication_string=password('12345')
//重要的事情说三遍 “不要省略password、不要省略password、不要省略password”

7、退出 mysql 并且执行 systemctl stop mysqld 停止mysql运行

8、将步骤3中添加的语句删除;

9、再重启mysql即可正常使用密码进入;

你可能感兴趣的:(mysql,linux,数据库)