解决思路:删除root 用户,新增admini用户,并赋予MySQL 最高权限。
具体步骤如下:
第一步:修改MySQL 登入限制:
# vim /etc/my.cnf
在[mysqld]的末尾追加上一句:skip-grant-tables
保存并退出
第二步:重新启动MySQL服务
#systemctl restart mysqld
第三步:登入MySQL 删除root 用户,新增admini 用户
#mysql
mysql> delete from user where user='root'; // 删除'root'用户
Query OK, 1 row affected (0.04 sec)
mysql> select user,host from user; // 查询用户信息
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
3 rows in set (0.00 sec)
mysql> flush privileges; // 权限刷新
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'admini'@'%' IDENTIFIED with mysql_native_password BY '123456'; // 创建admini 用户和密码 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements // 创建admini 用户提示密码不符合规则,密码规则需要调整。
第四步:调整密码规则
mysql> SHOW VARIABLES LIKE 'validate_password%'; // 查看密码规则关键字段
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
mysql> set global validate_password.policy=0; //设置密码安全等级,0 是最低
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=4; // 设置密码最低长度,4
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; //权限刷新
Query OK, 0 rows affected (0.01 sec)
第五步:创建admini 用户,并赋予MySQL 最高权限
mysql> CREATE USER 'admini'@'%' IDENTIFIED with mysql_native_password BY '123456'; // 创建admini 用户和密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admini'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
第六步:再次修改MySQL 登入限制:
去除[mysqld] 中的skip-grant-tables ,重新启动MySQL服务。