Centos7 mysql忘记密码解决办法

1.vim /etc/my.cnf 进行编辑,加入skip-grant-tables

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

skip-grant-tables  加入此句,登录无需密码

#Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

2、systemctl restart mysqld 重启Mysql

[root@cuichengjie ~]# systemctl restart mysqld

3.mysql 登录 无需密码

[root@cuichengjie ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

4、输入命令重置密码

update mysql.user set authentication_string=PASSWORD('123456') where User='root';
更改密码为123456
再使用flush privileges;

5、重新进入文档,将写入命令注释,再重启Mysql

发布了7 篇原创文章 · 获赞 0 · 访问量 124

猜你喜欢

转载自blog.csdn.net/user_cui/article/details/104440991