MySQL8.0 新特性

MySQL8.0引入了许多新特性,如角色管理、优化器索引、通用表表达式和窗口函数。认证插件更新为caching_sha2_password,支持隐藏和降序索引。还增加了密码历史管理和原子DDL操作,增强了InnoDB,包括集成数据字典和自增列持久化。JSON功能也得到增强,支持内联路径操作和聚合函数。
摘要由CSDN通过智能技术生成

MySQL8.0 新特性

创建用户及授权

MySQL8.0 创建用户和用户授权的命令需要分开执行:

--创建
create user 'andy'@'%' identified by 'andy@2019';
--授权
grant all privileges on *.* to 'andy'@'%'

在MySQL5.7中只需要使用 grant all 语句就可以创建用户及授权:

grant all privileges on *.* to 'andy'@'%' identified by 'andy@2019';

认证插件更新

MySQL 8.0 中默认的身份认证插件是 caching_sha2_password,替代了之前的 mysql_native_passsword

查看认证插件:

show variables like 'default_authentication_plugin%'

select user,host,plugin from mysql.user

如果在mysql8.0 中仍然想使用原来认证插件

方式一:

可以在配置文件中进行修改

查看配置文件:

more /etc/my.cnf

在这里插入图片描述

将配置文件中被注释掉的 default_authentication_plugin=mysql_native_password 放开注释,重启服务即可

方式二:

alter user 'andy'@'%' identified with mysql_native_password by 'andy@2019'

密码管理

MySQL8.0 允许限制重复使用之前使用过的密码

password_history = 3 表示最近使用过的密码不能重复使用三次(默认是0)

password_reuse_interval = 90 表示最近90天内不用使用重复使用过的密码(默认是0)

password_require_current = ON 表示修改用户密码时,需要提供当前用户的密码(默认是OFF)

查看相关参数 :

show variables like 'password%'
设置密码重用
vi /etc/my.cnf

在配置文件中配置上面的即可参数

方式一: 设置全局密码重用策略

--persist 永久,通过persist设置之后服务重启也是存在的
set persist password_history=6

-- 查看配置
--mysql8.0是通过自动增加配置文件来实现持久化
more /var/lib/mysql/mysql-auto.cnf

方式二: 根据某个不同的用户设置自定义的密码重用策略

alter user 'andy'@'%' password history 5

select user,host,Password_reuse_history from mysql.user

desc mysql.password_history

--修改密码
alter useruser() identified by 'andy@2020' replace  'andy@2022'

角色管理(MySQL8.0新增的功能)

--创建角色
create role 'write_role'

--授权
grant insert,update,delete on testdb.* to 'write_role'

--创建用户
create user 'user1' identified by 'andy@123'

grant select on testdb.* to 'write_role'

--启用角色
set role 'write_role'

--设置默认的角色
set default role 'write_role' to 'user1'

select * from mysql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值