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