首先登陆mysql, 一般命令格式为:mysql> set password for 用户名@localhost = password(‘新密码’);
代码如下(示例):
mysql> set password for root@localhost = password('123');格式:mysqladmin -u用户名 -p旧密码 password 新密码
代码如下(示例):
mysqladmin -uroot -p123456 password 123登陆进入mysql,
代码如下(示例):
mysql> use mysql; mysql> update user set password=password('123') where user='root' and host='localhost'; mysql> flush privileges;代码如下(示例):
mysql> ALTER USER root@localhost identified by '123';登录进入mysql,输入命令mysql>select @@validate_password_policy;该命令为了查看密码的安全等级;
mysql>select @@validate_password_policy;查看密码相关参数;
mysql> show variables like 'validate_password%'; +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +--------------------------------------+--------+ 6 rows in set (0.00 sec)validate_password_dictionary_file:用于验证密码强度的字典文件路径; validate_password_length:密码最小长度,参数默认为8,它有最小值的限定; validate_password_mixed_case_count:密码至少要包含的大写字母和小写字母的个数; validate_password_number_count 密码至少要包含的数字个数; validate_password_policy:密码强度等级检查;(默认是1,即MEDIUM) validate_password_special_char_count:密码至少要包含的特殊字符个数;
mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_mixed_case_count=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_number_count=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_special_char_count=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=3; Query OK, 0 rows affected (0.00 sec)1.修改密码强度等级为0,即是LOW; 2.修改密码至少要包含的大写字母和小写字母的个数为0; 3.修改密码至少要包含的数字个数为0; 4.修改密码至少要包含的特殊字符的个数为0; 5.修改密码的长度最小个数为3;
修改后的密码相关参数;
mysql> show variables like 'validate_password%'; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_dictionary_file | | | validate_password_length | 3 | | validate_password_mixed_case_count | 0 | | validate_password_number_count | 0 | | validate_password_policy | LOW | | validate_password_special_char_count | 0 | +--------------------------------------+-------+ 6 rows in set (0.00 sec)