MySQL80重置密碼


 

Windows:

 

一:

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

     

  2. 查詢mysql80服務的配置
    sc qc mysql80

     

     

  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

     

     

  6. taskkill /f /im mysqld*

     

     

  7. 啟動服務
    sc start mysql80

     

     

  8. 查詢服務狀態
    sc query mysql80

     

     

     

二:

  使用skip-grant-tables跳過權限檢查表方式

  1. mysqld --skip-grant-tables

     

     MySQL8.0后默認的datadir位於        C:\ProgramData\MySQL\MySQL Server 8.0\Data
    配置文件中很清楚的寫明

     

     但是上述方式啟動的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"

     

     根據提示在NT OS系統中需要使用--shared-memory 或者 --named-pipe選項

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

     

     最終進入到了系統

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

     

     首先要刷新權限表

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

    這種模式下只能修改localhost的密碼

     

     

三:
  通過初始化數據庫

  1. mysqld --initialize --console

     初始化的目錄不能存在,否則失敗,生成了一個臨時密碼

  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';

     

  4. mysql高版本已經廢棄了password字段和password方法
  5. 至此,可以無密碼登錄了修改了,但是此種方式不是修改的源數據庫密碼

 

認證相關操作:

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

     

     

  2. 查看當前用戶
    select user();

     

     

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

     

     

     ## 新密碼不能和前面三次的密碼相同 password_history = 3 ; ## 新密碼不能和前面九十天內使用的密碼相同 password_reuse_interval = 90 ; ## 默認為off;為on 時 修改密碼需要用戶提供當前密碼 (開啟后修改密碼需要驗證舊密碼,root 用戶不需要) password_require_current = on ;

     

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

    配置寫在了 data 下的

     

     mysqld-auto.cnf中

  5. 臨時修改
    set global password_history=2;
    

     

 

Linux:

  1. 初始密碼儲存在/var/log/mysqld.log

     

     

     

  2. MySQL8.0密碼驗證插件有所變化
    show variables like 'validate_passowrd';

     

     

  3. 設置密碼驗證策略
    set @@global.validate_password.policy=low; set @@global.validate_password.length=1;

     

     最短長度為4

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM