MySQL忘记密码

1. 忘记mysql密码后很苦恼

2. 修改mysql 配置文件

root@localhost:/etc/mysql/mysql.conf.d# cd /etc/mysql/mysql.conf.d
root@localhost:/etc/mysql/mysql.conf.d# vim mysql.cnf
# 在[mysqld]下增加
skip-grant-tables
# 就是在启动mysql时不启动grant-tables,授权表

3. 重启mysql服务

service mysql restart

4. mysql直接进入命令行

root@localhost:/etc/mysql/mysql.conf.d# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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>

5. 修改密码

use mysql;
update mysql.user set authentication_string=password('你想输入的密码') where user='root';
--不要忘记(或删掉第二步添加的skip-grant-tables后,重启mysql服务)
flush privileges;
  • flush privileges;
    • 如:在新创建用户后,不使用该命令刷新user_privileges表则无法登陆
    • 一是重启mysql服务,二是使用flush privileges在插入之后刷新系统权限相关表

6. 删除第二步中添加的mysql配置文件中的授权表配置

7. 重启mysql服务

service mysql restart

ps: root权限丢了之后数据库分分钟丢...嗯...

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容