Windows:
一:
-
c:/mysql/mysql-init.txt alter user 'root'@'localhost' identified by 'cruces';
- 查詢mysql80服務的配置
sc qc mysql80
-
mysqld --defaults-file="c:/programdata/mysql/mysql server 8.0/my.ini" --init-file=c:/mysql/mysql-init.txt --console
- 經過上面的操作,'root'@'localhost'的密碼已經修改為cruces,下面結束臨時啟動的進程
-
tasklist | findstr mysqld
-
taskkill /f /im mysqld*
- 啟動服務
sc start mysql80
- 查詢服務狀態
sc query mysql80
二:
使用skip-grant-tables跳過權限檢查表方式
-
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目錄指向安裝時的目錄 -
mysqld --skip-grant-tables --console --datadir="C:/ProgramData/MySQL/MySQL Server 8.0/Data"
根據提示在NT OS系統中需要使用--shared-memory 或者 --named-pipe選項
-
mysqld --skip-grant-tables --console --datadir="C:/ProgramData/MySQL/MySQL Server 8.0/Data" --shared-memory
最終進入到了系統
-
alter user root@'%' identified by 'coalesce';
首先要刷新權限表
-
flush privileges; alter user root@localhost identified by 'coalesce';
這種模式下只能修改localhost的密碼
三:
通過初始化數據庫
-
mysqld --initialize --console
初始化的目錄不能存在,否則失敗,生成了一個臨時密碼
-
mysqld --skip-grant-tables --console --shared-memory
-
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高版本已經廢棄了password字段和password方法
- 至此,可以無密碼登錄了修改了,但是此種方式不是修改的源數據庫密碼
認證相關操作:
- 查詢用戶加密插件
select host,user,plugin,authentication_string from mysql.user;
- 查看當前用戶
select user();
- 查看密碼管理策略
show variables like 'password%';
## 新密碼不能和前面三次的密碼相同 password_history = 3 ; ## 新密碼不能和前面九十天內使用的密碼相同 password_reuse_interval = 90 ; ## 默認為off;為on 時 修改密碼需要用戶提供當前密碼 (開啟后修改密碼需要驗證舊密碼,root 用戶不需要) password_require_current = on ;
- 永久修改密碼策略
set persist password_history=1;
配置寫在了 data 下的
mysqld-auto.cnf中
- 臨時修改
set global password_history=2;
Linux:
- 初始密碼儲存在/var/log/mysqld.log
- MySQL8.0密碼驗證插件有所變化
show variables like 'validate_passowrd';
- 設置密碼驗證策略
set @@global.validate_password.policy=low; set @@global.validate_password.length=1;
最短長度為4