zoukankan      html  css  js  c++  java
  • 忘记MySQL的root密码的解决方法

    经常会有朋友或者同事问起,MySQL 的 root 密码忘了,不知道改怎么办。

    其实解决方法很简单,下面是详细的操作步骤。

    (1)修改配置文件my.cnf,在配置文件[mysqld]下添加skip-grant-tables,重启MySQL服务即可免密码登录

      其中--skip-grant-tables 选项前面曾经介绍过,意思是启动 MySQL 服务的时候跳过权限表认证。 启动后,连接到 MySQL 的 root 将不需要口令。

    # SERVER SECTION
    # ----------------------------------------------------------------------
    #
    # The following options will be read by the MySQL Server. Make sure that
    # you have installed the server correctly (see above) so it reads this 
    # file.
    #
    [mysqld]
    
    skip-grant-tables

    (2)用空密码的 root 用户连接到 MySQL,并且更改 root 口令:

    [root@localhost mysql]# mysql -uroot
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 53
    Server version: 5.0.41-community-log MySQL Community Edition (GPL)
    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
    mysql>
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';  
     ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    mysql> update user set authentication_string = NULL where user = 'root';
    Query OK, 1 row affected (0.00 sec)

    上面是先用grant的方式修改root密码,但是由于使用了配置了skip-grant-tables 选项,使用“alter user”命令更改密码失败,直

    接更新 user 表的 authentication_string字段后更改密码成功。

    (3)到my.cnf 中删除skip-grant-tables选项,然后直接用mysql -uroot免密码登录后,在执行如下语句重设密码

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';  

    (4)重新用 root 登录时,必须输入新口令。

     

      MySQL 中,密码丢失后无法找回,只能通过上述方式修改密码。

  • 相关阅读:
    高级数据结构(一)----并查集
    分享复杂的线性动态规划问题(一)
    分享利用微信公众号做淘宝客返利机器人系统的3个技巧
    淘宝京东拼多多三合一cms源码怎么搭建优惠券网站
    微信公众号怎么查京东优惠券之3步搭建自己的找券机器人
    【职场提示】什么时间提出涨薪资更合适?
    项目管理之Git
    快速排序,数组去重
    信息安全风险治理——制度与标准篇
    浅谈漏洞管理实践
  • 原文地址:https://www.cnblogs.com/ryanzheng/p/9348723.html
Copyright © 2011-2022 走看看