zoukankan      html  css  js  c++  java
  • Mysql8.0忘记密码

    问题背景:

    在ubuntu18上装完mysql8后,初始化时没有给随机密码,也无法设置密码;

    第一步:修改/etc/my.cnf配置文件,在[mysqld]ui后加上如下语句:

    skip-grant-tables

    第二步免密登录到mysql上,

    第三步:给root用户重置秘密;

    3.1首先查看当前root用户相关信息,在mysql数据库的user表中

    select host, user, authentication_string, plugin from user

    host: 允许用户登录的ip‘位置’%表示可以远程;

    user:当前数据库的用户名;

    authentication_string: 用户密码;在mysql 5.7.9以后废弃了password字段和password()函数;

    plugin: 密码加密方式;

    3.2 如果当前root用户authentication_string字段下有内容,先将其设置为空;

      1. use mysql;  
      2.  update user set authentication_string='' where user='root';
      3. update user set password_expired='N' where user='root';
      4.  flush privileges;
      5. exit;
      6. 3.3 退出mysql, 删除/etc/my.cnf文件最后的 skip-grant-tables 重启mysql服务;
      7. service mysqld restart 
      8. 3.4 使用root用户进行登录,因为上面设置了authentication_string为空,所以可以免密码登录;
        1.   

      

    3.5使用ALTER修改root用户密码

    ALTER user 'root'@'localhost' IDENTIFIED BY 'Zhige123#';

    至此修改成功; 从新使用用户名密码登录即可;

     

  • 相关阅读:
    #define IOFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
    互联网地址处理例程
    Android系统工程模式启动过程详解
    知识填充
    git 本地回退
    理解JS中的Promise对象
    MySQL server version for the right syntax to use near 'identified
    尾递归要注意的点
    事件捕获和事件冒泡的理解
    v 2ra-y_build_a_sever_in_vltru
  • 原文地址:https://www.cnblogs.com/new-journey/p/13163148.html
Copyright © 2011-2022 走看看