暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL 8.0用户创建及密码策略

原创 黄堋 2020-06-19
2186

image.png
测试版本为8.0.20
使用grant隐式创建用户:

mysql> grant select on sys.* to ‘dblight’@‘127.0.0.1’ identified by ‘123’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘1234’’ at line 1

发现报错,去掉identified by关键字:
mysql> grant select on sys.* to ‘dblight’@‘127.0.0.1’;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
结合报错信息,得出结论:8.0开始已经取消了grant隐身创建用户的功能,所以需要采用先创建再授权的方式:
mysql> create user ‘perf’@‘127.0.0.1’ identified by ‘123’;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
发现8.0默认有密码策略,查询策略参数
image.png
可以看到策略参数和8.0之前有一定的却别,之前为validate_password_,现在是validate_password.,不过原理还是类似的,策略模式内容如下:
image.png
所以我们想最低成都去限制密码策略,可以吧policy改成0,length改成1.
mysql> set global validate_password.policy=0 ;
Query OK, 0 rows affected (0.01 sec)
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)
设置完毕之后再次创建用户依然报错:
mysql> create user ‘perf’@‘127.0.0.1’ identified by ‘123’;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

查询密码策略:
image.png
发现length变成了4而不是我们设置的1,我反复测试了将length改为0和1也都是4,故推断出8.0以后限制密码大于4位。
将密码调整为4位后可以正常创建和授权:
mysql> create user ‘dblight’@‘127.0.0.1’ identified by ‘1234’;
Query OK, 0 rows affected (0.00 sec)

mysql> grant select on sys.* to ‘dblight’@‘127.0.0.1’;
Query OK, 0 rows affected (0.01 sec)

最后修改时间:2020-06-19 17:04:46
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论