zoukankan      html  css  js  c++  java
  • Mysql忘记root密码怎么办?(已解决)

    为了写这篇文档,假装一下忘记密码!!!!

    首先我数据库是正常的,可以使用。

    root@localhost:~# mysql -uroot -p
    mysql>
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)
    mysql> exit
    Bye 

    假如我忘记了密码,现在无法登陆数据库,会提示密码错误。

    root@localhost:~# mysql -uroot -p
    Enter password:
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 

    1)、首先安全停掉mysql服务

    root@localhost:~# /etc/init.d/mysql stop
    Shutting down MySQL
    .... *

    2)、编辑配置文件,在[mysqld]添加skip-grant-tables

    (--skip-grant-tables 的意思是启动 MySQL 服务的时候跳过权限表认证)

    3)、启动mysql服务

    root@localhost:~# /etc/init.d/mysql start
    Starting MySQL
    ..... *

    4)、登录数据库并修改密码

    root@localhost:~# mysql -uroot
    mysql>
    mysql> update mysql.user set password=PASSWORD('jeqThs1qOVbHGRz0') where user='root';
    Query OK, 2 rows affected (0.00 sec)
    Rows matched: 4  Changed: 2  Warnings: 0
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit
    Bye

    5)、再次编辑配置文件,删除skip-grant-tables

    root@localhost:~# vim /etc/mysql/my.cnf

    6)、修改之后重启mysql服务

    root@localhost:~# /etc/init.d/mysql restart
    Shutting down MySQL
    .... *
    Starting MySQL
    ..... *

    7)、此时就可以用新密码登录啦

    root@localhost:~# mysql -uroot -pjeqThs1qOVbHGRz0
    mysql>
    mysql> exit
    Bye
  • 相关阅读:
    Robot Framework自动化测试(六)--- robotremoteserver使用
    PHP实现简易blog
    Pillow实现图片对比
    Django快速开发之投票系统
    web接口测试之GET与POST请求
    接口测试实践
    Python单元测试框架之pytest -- 断言
    stack 的优势
    如何使用 stack?- 每天5分钟玩转 Docker 容器技术(112)
    什么是 stack?- 每天5分钟玩转 Docker 容器技术(111)
  • 原文地址:https://www.cnblogs.com/zhaomeng/p/10470197.html
Copyright © 2011-2022 走看看