
测试版本为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默认有密码策略,查询策略参数

可以看到策略参数和8.0之前有一定的却别,之前为validate_password_,现在是validate_password.,不过原理还是类似的,策略模式内容如下:

所以我们想最低成都去限制密码策略,可以吧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
查询密码策略:

发现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)




