Windows:

 

一:

  1. c:/mysql/mysql-init.txt
    
    alter user 'root'@'localhost' identified by 'cruces';

     

  2. 查询mysql80服务的配置
    sc qc mysql80

    MySQL: Reset Password

     

     

  3. mysqld --defaults-file="c:/programdata/mysql/mysql server 8.0/my.ini" --init-file=c:/mysql/mysql-init.txt --console

     

  4. 经过上面的操作,'root'@'localhost'的密码已经修改为cruces,下面结束临时启动的进程
  5. tasklist | findstr mysqld

    MySQL: Reset Password

     

     

  6. taskkill /f /im mysqld*

    MySQL: Reset Password

     

     

  7. 启动服务
    sc start mysql80

    MySQL: Reset Password

     

     

  8. 查询服务状态
    sc query mysql80

    MySQL: Reset Password

      

二:

  使用skip-grant-tables跳过权限检查表方式

  1. mysqld --skip-grant-tables

    MySQL: Reset Password

     

     MySQL8.0后默认的datadir位于        C:\ProgramData\MySQL\MySQL Server 8.0\Data
    配置文件中很清楚的写明
    MySQL: Reset Password

     

     但是上述方式启动的mysqld默认datadir为      C:\Program Files\MySQL\MySQL Server 8.0
    此目录默认并不存在,因此我们使用--datadir把其database root目录指向安装时的目录

     
  2. mysqld --skip-grant-tables --console --datadir="C:/ProgramData/MySQL/MySQL Server 8.0/Data"

    MySQL: Reset Password

     

     根据提示在NT OS系统中需要使用--shared-memory 或者 --named-pipe选项

  3. mysqld --skip-grant-tables --console --datadir="C:/ProgramData/MySQL/MySQL Server 8.0/Data" --shared-memory

    MySQL: Reset Password

     

     最终进入到了系统

  4. alter user root@'%' identified by 'coalesce';

    MySQL: Reset Password

     

     首先要刷新权限表

  5. flush privileges;
    alter user root@localhost identified by 'coalesce';

    这种模式下只能修改localhost的密码
    MySQL: Reset Password

     

     

三:
  通过初始化数据库

  1. mysqld --initialize --console

    MySQL: Reset Password

     初始化的目录不能存在,否则失败,生成了一个临时密码

  2. mysqld --skip-grant-tables --console --shared-memory
  3. flush privileges;
    use mysql;
    desc user;
    select host,user,authentication_string from user;
    update user set authentication_string='' where user='root';
    alte user root@localhost identified with mysql_native_password by 'coalesce';

    MySQL: Reset Password

     

  4. mysql高版本已经废弃了password字段和password方法
  5. 至此,可以无密码登录了修改了,但是此种方式不是修改的源数据库密码

 

认证相关操作:

  1. 查询用户加密插件
    select host,user,plugin,authentication_string from mysql.user;

    MySQL: Reset Password

     

     

  2. 查看当前用户
    select user();

    MySQL: Reset Password

     

     

  3. 查看密码管理策略
    show variables like 'password%';

    MySQL: Reset Password

     

     

        ## 新密码不能和前面三次的密码相同
        password_history = 3 ; 
         
        ## 新密码不能和前面九十天内使用的密码相同
        password_reuse_interval = 90 ; 
         
        ## 默认为off;为on 时 修改密码需要用户提供当前密码 (开启后修改密码需要验证旧密码,root 用户不需要)
        password_require_current = on ;

     

  4. 永久修改密码策略
    set persist password_history=1;

    配置写在了 data 下的MySQL: Reset Password

     

     mysqld-auto.cnf中

  5. 临时修改
    set global password_history=2;
    

     

 

Linux:

  1. 初始密码储存在/var/log/mysqld.log
    MySQL: Reset Password

    MySQL: Reset Password

     

     

     

  2. MySQL8.0密码验证插件有所变化
    show variables like 'validate_passowrd';

    MySQL: Reset Password

     

     

  3. 设置密码验证策略
    set @@global.validate_password.policy=low;
    set @@global.validate_password.length=1;

    MySQL: Reset Password

     

     最短长度为4

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-09-28
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
猜你喜欢
  • 2022-03-05
  • 2022-12-23
  • 2022-01-12
  • 2021-10-24
  • 2021-11-29
  • 2021-07-05
  • 2022-12-23
相关资源
相似解决方案