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
  • 相关阅读:
    websocket协议
    vue组件之间的传值
    vue中非父子组件的传值bus的使用
    $.proxy的使用
    弹性盒模型display:flex
    箭头函数与普通函数的区别
    粘贴到Excel的图片总是有些轻微变形
    centos rhel 中文输入法的安装
    vi ,默认为 .asm .inc 采用nasm的语法高亮
    how-to-convert-ppk-key-to-openssh-key-under-linux
  • 原文地址:https://www.cnblogs.com/zhaomeng/p/10470197.html
Copyright © 2011-2022 走看看