码迷,mamicode.com
首页 > 数据库 > 详细

MySQL 5.7 数据库的忘记 root 登录密码处理

时间:2020-06-04 12:12:19      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:pass   直接   tar   localhost   --   restart   mys   配置   cut   

在 /etc/my.cnf 配置文件中添加 skip-grant-tables 绕开 MySQL 5.7 数据库密码验证
echo skip-grant-tables >> /etc/my.cnf

/etc/init.d/mysqld restart

直接使用 mysql 命令登录 MySQL5.7 数据库并修改 root 登录密码
mysql
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘password‘;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘password‘;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

使用新密码 password 登录 MySQL5.7 数据库
mysql -uroot -ppassword

删掉 /etc/my.cnf 里的 skip-grant-tables
sed -i -e ‘/skip-grant-tables/d‘ /etc/my.cnf
/etc/init.d/mysqld restart

MySQL 5.7 数据库的忘记 root 登录密码处理

标签:pass   直接   tar   localhost   --   restart   mys   配置   cut   

原文地址:https://blog.51cto.com/sanyuanyanjin/2501163

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!